| |

VerySource

 Forgot password?
 Register
Search
View: 1288|Reply: 7

Small question, how to sort by query results in SQL?

[Copy link]

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-24 09:00:01
| Show all posts |Read mode
I have the table XXX and the field Age (int). The existing query is as follows:
select Age 'Age', Age-5 'Age 2' from XXX;

Now I want to sort by 'age 2, the following wording is incorrect:
select Age 'Age', Age-5 'Age 2' from XXX order by 'Age 2';

How do I do that?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-7 11:00:01
| Show all posts
order by
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-5-7 11:30:01
| Show all posts
select Age as [age], Age-5 as [age 2]
from XXX
order by [age 2]
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-7 13:00:02
| Show all posts
Less as?
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-5-7 16:15:01
| Show all posts
select * from (select Age as age, Age-5 as age 2 from XXX) a order by age 2
Reply

Use magic Report

0

Threads

48

Posts

30.00

Credits

Newbie

Rank: 1

Credits
30.00

 China

Post time: 2020-5-7 20:15:01
| Show all posts
select Age 'age', Age-5 'age 2' from XXX order by Age-5
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-5-8 09:45:01
| Show all posts
If I want to query (Age-5)> 20, how do I write it?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-22 22:30:01
| Show all posts
select Age'age',Age-5'age 2'from XXX
where age-5>20
order age-5
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list