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 分為兩個部分:數(shù)據(jù)操作語言 (DML) 和 數(shù)據(jù)定義語言 (DDL)炼七。
SQL (結(jié)構(gòu)化查詢語言)是用于執(zhí)行查詢的語法。但是 SQL 語言也包含用于更新盟步、插入和刪除記錄的語法狂鞋。
查詢和更新指令構(gòu)成了 SQL 的 DML 部分:
SELECT - 從數(shù)據(jù)庫表中獲取數(shù)據(jù)
UPDATE - 更新數(shù)據(jù)庫表中的數(shù)據(jù)
DELETE - 從數(shù)據(jù)庫表中刪除數(shù)據(jù)
INSERT INTO - 向數(shù)據(jù)庫表中插入數(shù)據(jù)
SQL 的數(shù)據(jù)定義語言 (DDL) 部分使我們有能力創(chuàng)建或刪除表格。我們也可以定義索引(鍵)劫狠,規(guī)定表之間的鏈接拴疤,以及施加表間的約束。
SQL 中最重要的 DDL 語句:
CREATE DATABASE - 創(chuàng)建新數(shù)據(jù)庫
ALTER DATABASE - 修改數(shù)據(jù)庫
CREATE TABLE - 創(chuàng)建新表
ALTER TABLE - 變更(改變)數(shù)據(jù)庫表
DROP TABLE - 刪除表
CREATE INDEX - 創(chuàng)建索引(搜索鍵)
DROP INDEX - 刪除索引