select client,ID,taskdate from 表名 order BY client asc,taskdate,ID desc(如果让client为降序的话order by改成group by,asc改成desc,ID要升序desc改成asc)
将字段依次写在order by 后面即可 , 中间用逗号隔开
select * from 表 order by time , name
select * from 表 order by time asc , name asc
select * from 表 order by time desc , name desc
select * from 表 order by time asc , name desc
select * from 表 order by time desc , name asc
(注: asc 表示升序 , desc表示降序 , 未明确写明排序方式时默认是升序 )
与之类似的语法是 group by , 按多个字段分组时 , 也是依次将多个字段写在group by 的后面 , 并用逗号隔开 , 范例如下:
select time , name , sum(*) from 表 group by time , name
转载请注明:落伍老站长 » SQL语句怎么写?先按时间排序,再按姓名排序?