MySQ练习

表名称比较长时,可以通过别名简化

SELECT c.orderTime,c.shishou,c.totalPrice,c.cid=1164 FROM cash_order c WHERE c.cid=1164

FROM  cash_order c 即设置表cash_order的别名为c

如果有多个条件,用AND 连接

SELECT c.orderTime,c.shishou,c.totalPrice,c.cid=1164 FROM cash_order c WHERE c.cid=1164 AND c.totalPrice<5 and c.totalPrice>=1

排序时,用ORDER BY,默认是升序(ASC),如果要倒序显示,加DESC

SELECT c.orderTime,c.shishou,c.totalPrice,c.cid=1164 FROM cash_order c WHERE c.cid=1164 AND c.totalPrice<5 and c.totalPrice>=1 ORDER BY c.totalPrice DESC

限制查询的数量,用关键字LIMIT

SELECT c.orderTime,c.shishou,c.totalPrice,c.cid=1164 FROM cash_order c WHERE c.cid=1164 AND c.totalPrice<5 and c.totalPrice>=1 ORDER BY c.totalPrice DESC LIMIT 10

查询结果如下:

猜你喜欢

转载自www.cnblogs.com/may18/p/12430103.html