问题描述
我想使用两个标准查询数据库行:A 第一,B 第二.即:Order by A,如果A值相同,Order by B作为第二标准sql怎么写?例子:查询表:
I want to query db rows using two standards: A first, B second.That is: Order by A, if A values are the same, Order by B as the second standardHow to write the sql?Example:query table:
id | A | B
_ _ _ _ _ _
1 | 1 | 1
_ _ _ _ _ _
2 | 2 | 2
_ _ _ _ _ _
3 | 2 | 1
_ _ _ _ _ _
4 | 3 | 1
查询结果:
id
1
3
2
4
推荐答案
Order by 用于对 ASC 中的表的结果进行排序 |基于一个或多个列名的 DESC.默认按 ASC 排序.
Order by is used to sort the result from a table in ASC | DESC based on one or more column names. It sorts by ASC in default.
示例:
Select * from Table1 order by A,B
在这个例子中,Table1 的结果在 ASC 中按 A 和 B 排序.如果 A 具有相同的值,那么结果将在 ASC 中按 B 排序
In this example the results from Table1 is sorted in ASC by A as well as B. If A has the same values, then the results will be sorted by B in ASC
这篇关于使用Order by A查询行,如果A值相同,Order by B作为第二标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!