select o.order_num,c.cust_name from customers as c,orders as o where c.cust_id = o.cust_id order by c.cust_name,o.order_num ;
select o.order_num,c.cust_name from customers as c inner join orders as o on c.cust_id = o.cust_id order by c.cust_name,o.order_num ;
select o.order_num,c.cust_name,oi.quantity * oi.item_price as ordertotal
from customers as c
inner join orders as o on c.cust_id = o.cust_id
inner join orderitems as oi on oi.order_num = o.order_num
order by c.cust_name,o.order_num ;
select c.cust_name,o.order_num,
( select sum( oi.quantity * oi.item_price )
from orderitems as oi where 0.order_num = oi order_num group by oi.order_num ) as ordertotal
from customers as c,orders as o where c.cust_id = o.cust_id;
select c.cust_email
from customers as c, orderitems as oi,orders as o
where oi.order_num = o.order_num and o.cust_id = c.cust_id
and oi.prod_id = 'ANV01';
select c.cust_name,sum(oi.quantity * oi.item_price) as 订单金额
from customers as c, orderitems as oi,orders as o
where oi.order_num = o.order_num and o.cust_id = c.cust_id
group by oi.order_num having 订单金额 < 1000;
五、练习2
1.使用INNERJOIN编写一条 SOL 语句来检索客户名称(cust_name in客户)以及每个订单的所有订单号(订单中的order num )
select c.cust_name,o.order_num from customers as c,orders as o
where o.cust_id = c.cust_id ;
2.修改您刚刚创建的 SOL 语句以列出所有客户,甚至是那些没有客户的客户命令。
select c.cust_name,o.order_num from orders as o
RIGHT OUTER JOIN customers as c
on o.cust_id = c.cust_id ;