(19) 查找在2008年3月中有销售记录的客户编号、名称和订单总额。 命令:
SELECT a.CustomerNo ,a.CustomerName ,orderDate ,sum(quantity *price )as 金额 FROM Customer a,OrderMaster b,OrderDetail c
WHERE a.CustomerNo =b.CustomerNo and b.orderNo =c.orderNo and year(orderDate )=2008 and month(orderDate )=3 GROUP BY a.CustomerNo ,a.CustomerName ,orderDate 结果:
(20) 使用左外连接查找每个客户的客户编号、名称、订货日期、订单金额,其中订货日期不要显示时间,日期格式为“yyyy-mm-dd”,按客户编号排序,同一客户再按订单金额降序排序输出。 命令:
SELECT a.CustomerNo ,a.CustomerName ,ISNULL(convert(char(10),orderDate ,120),'') Date