- 查询价格从高到低的顺序,价格相同的排名并列:
SELECT TNAME, PRICE
FROM fruit_table
ORDER BY PRICE DESC
- 假设小明有100元,需要购买两种水果,利用SQL查询有几种购买方案,查询结果显示有几种解决方案:
SELECTCOUNT(*)
FROM fruit_table t1, fruit_table t2
WHERE t1.TNAME <> t2.TNAME AND t1.PRICE + t2.PRICE <= 100
SELECT TNAME, PRICE
FROM fruit_table
ORDER BY PRICE DESC
SELECTCOUNT(*)
FROM fruit_table t1, fruit_table t2
WHERE t1.TNAME <> t2.TNAME AND t1.PRICE + t2.PRICE <= 100