一、查询
1.order by XX DESC 按照XX降序
2.distinct 去重
3.order by XX,XXX DESC
如果XX条件一样,按照XXX降序
4.通配符查询
XX like "%toy%"
二.函数
1.substring 子串 substring(XX,1,2)
` concat拼接 concat(A,B)
upper大写 upper(A)`
计算某列的和Sum(A)
计算某列的行数Count(A)
having必须和group by一起使用
三.连接
(1)group by 需要包含select所有出现的字段:
#返回顾客名称和相关订单号以及每个订单的总价
select cust_name,Orders.order_num,sum(quantity*item_price) OrderTotal from Customers join Orders
on Customers.cust_id=Orders.cust_id
join OrderItems on Orders.order_num=OrderItems.order_num
group by cust_name,Orders.order_num
order by cust_name,Orders.order_num
(2)left join,right join,join区别
(3)union用法:拼接两个表,字段要一样
select prod_id,quantity from OrderItems where quantity = 100
union
select prod_id,quantity from OrderItems where prod_id like "BN%"
order by prod_id;