Home > database >  Hurry asked in a table with an SQL statement, please find out all of the data, query results sorted
Hurry asked in a table with an SQL statement, please find out all of the data, query results sorted

Time:10-06

In a table with an SQL statement, please find out all of the data, the query results sorted by designated user type first, and then according to the ascending order id

CodePudding user response:

 select * from t order by user type, id 

CodePudding user response:

This I tried, not yet

CodePudding user response:

refer to the second floor lms279151398 response:
this I've tried, not yet

Describes in detail some, you specify a user type is what kind of

CodePudding user response:

Finally sort: 1 admin
7 the admin
3 the user
4 the user
6 the user
2 super user
5 super user

CodePudding user response:

reference 4 floor lms279151398 response:
last sort: 1 admin
7 the admin
3 the user
4 the user
6 the user
2 super user
5 super user

You this order is coming along? Users according to settle such an order?

CodePudding user response:

Are there any specific data, we give some to

CodePudding user response:

Data on the user's table and order are chaotic, sorting out the results according to specifications

CodePudding user response:

The create table aaa (
Did number (2),
Dname varchar2 (10)
);
Insert into aaa values (1, "admin");
Insert into aaa values (2, 'super user');
Insert into aaa values (3, "user");
Insert into aaa values (4, 'user');
Insert into aaa values (5, 'super user');
Insert into aaa values (6, "user");
Insert into aaa values (7, "admin");

CodePudding user response:

 
SQL>
SQL> The create table aaa (
2 did number (2),
3 dname varchar2 (10)
4);
The Table created
SQL> The begin
2 insert into aaa values (1, "admin");
Insert into 3 aaa values (2, 'super user');
Insert into 4 aaa values (3, "user");
5 the insert into aaa values (4, 'user');
6 insert into aaa values (5, 'super user');
7 the insert into aaa values (6, "user");
8 the insert into aaa values (7, "admin");
9 the end;
10/
PL/SQL procedure successfully completed
SQL> Select * from aaa
2 the order by decode (dname, 'admin', 1, 'user', 2, 'super user', 3), did.
DID DNAME
-- -- -- -- -- -- -- -- -- -- -- -- --
1 the admin
7 the admin
3 the user
4 the user
6 the user
2 super user
5 super user
7 rows selected
SQL> Drop table aaa.
Table dropped

SQL>

CodePudding user response:

references 9 f wmxcn2000 response:
 
SQL>
SQL> The create table aaa (
2 did number (2),
3 dname varchar2 (10)
4);
The Table created
SQL> The begin
2 insert into aaa values (1, "admin");
Insert into 3 aaa values (2, 'super user');
Insert into 4 aaa values (3, "user");
5 the insert into aaa values (4, 'user');
6 insert into aaa values (5, 'super user');
7 the insert into aaa values (6, "user");
8 the insert into aaa values (7, "admin");
9 the end;
10/
PL/SQL procedure successfully completed
SQL> Select * from aaa
2 the order by decode (dname, 'admin', 1, 'user', 2, 'super user', 3), did.
DID DNAME
-- -- -- -- -- -- -- -- -- -- -- -- --
1 the admin
7 the admin
3 the user
4 the user
6 the user
2 super user
5 super user
7 rows selected
SQL> Drop table aaa.
Table dropped

SQL>

If the data is very big, this kind of demand is the pit it is best to add a field, is used to specify sorting

CodePudding user response:

Thank you, I also do it! O O (studying studying) thank you

CodePudding user response:

Pit? How do you say this word? Can simply tell me?

CodePudding user response:

references to the tenth floor ghx287524027 response:
if the data is very big, this kind of demand is the pit it is best to add a field that is used to specify


The homework is, or is the transport of data between two systems, real business system, there will be another dimension table records the admin user, the dimension table sort field;
  • Related