Select
d.CompanyName, c.SubTotal, b.Weight
from
ProductAW b
JOIN
SalesOrderDetail a ON a.ProductID = b.ProductID
JOIN
SalesOrderHeader c ON c.SalesOrderID = a.SalesOrderID
JOIN
CustomerAW d ON d.CustomerID = c.CustomerID
WHERE
d.CompanyName IN ('Good Toys', 'Transport Bikes')
ORDER BY
c.SubTotal ASC;
// 输出
CompanyName SubTotal Weight
Transport Bikes 602.19 13213.08
Transport Bikes 602.19 88.00
Good Toys 880.35 1061.40
Good Toys 880.35 988.83
查询 #2:
SELECT
d.CompanyName, c.SubTotal, b.Weight
FROM
ProductAW b
JOIN
SalesOrderDetail a ON a.ProductID = b.ProductID
JOIN
SalesOrderHeader c ON c.SalesOrderID = a.SalesOrderID
JOIN
CustomerAW d ON d.CustomerID = c.CustomerID
WHERE
d.CompanyName IN ('Good Toys', 'Transport Bikes')
ORDER BY
c.SubTotal DESC;
结果:
CompanyName SubTotal Weight
Good Toys 880.35 1061.40
Good Toys 880.35 988.83
Transport Bikes 602.19 13213.08
Transport Bikes 602.19 88.00
两个查询的区别仅在于子句上ASC
的DESC
关键字。ORDER BY
请解释为什么Weight
列也用SubTotal
.
干杯,