COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
29
2001-09-10
13 466.500
07
2001-09-11
16
186.782
23
2001-09-11
12
459.162
Neáu muoán saép xeáp theo nhieàu coät (tröôøng), chæ caàn söû duïng daáu phaåy (,) ñeå phaân caùch caùc coät.
Ví duï 8-7: SELECT vôùi meänh ñeà Order by vôùi 2 coät döõ lieäu
Select OrderID , OrderDate, CustID, Amount
From tblOrders
Where Amount >1000
Order by OrderID,CustID DESC
Keát quaû traû veà nhö sau:
OrderID OrderDate
CustID
Amount
---------- --------------------------- --------
31 2001-09-16
13
459.525
30 2001-09-15
13
153.120
29 2001-09-10
13
466.500
28 2001-09-15
13
145.200
27 2001-09-14
13
603.033
26 2001-09-13
13
230.000
25 2001-09-11
13
244.904
24 2001-09-12
13
1.367.228
23 2001-09-11
12
459.162
19 2001-09-10
12
575.667
Neáu muoán saép xeáp theo nhieàu tröôøng keát hôïp, chæ caàn duøng thöù töï töøng coät caùch nhau baèng daáu
+.
Ví duï 8-8: SELECT vôùi meänh ñeà Order by hôïp 2 coät
/*-- Giaûm daàn theo soá OrderID vaø CustID */
Select OrderID , OrderDate, CustID, Amount
From tblOrders
Where Amount >1000
Order by OrderID + CustID DESC
Keát quaû traû veà nhö sau:
OrderID OrderDate
CustID
Amount
---------- --------------------------- --------
31 2001-09-16
13
459.525
30 2001-09-15
13
153.120
29 2001-09-10
13
466.500
28 2001-09-15
13
145.200
27 2001-09-14
13
603.033
26 2001-09-13
13
230.000
25 2001-09-11
13
244.904
24 2001-09-12
13
1.367.228
23 2001-09-11
12
459.162
19 2001-09-10
12
575.667
Neáu trong phaùt bieåu SQL daïng SELECT coù nhieàu baûng keát hôïp laïi vôùi nhau, baïn coù theå duøng
theâm teân baûng öùng vôùi coät cuûa baûng ñoù. Phaàn naøy seõ ñöôïc dieãn giaûi cuï theå hôn trong phaàn keá tieáp
(JOIN -Pheùp hôïp).
Giaùo vieân: Phaïm Höõu Khang