SQL的查询语句

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:33:00
p_order表中
订单ID 产品ID 数量 雇员ID 客户ID 订货日期
101 1 10 1 1 2007-7-8
102 2 20 1 2 2006-10-1
103 4 20 2 1 2008-10-12
104 5 5 3 4 2008-4-2
105 1 5 2 3 2005-1-1

product表中
产品ID 单价 存库量
1 2.3 200
2 1.5 400
3 3 300
4 40 100
5 200 150

提问:统计2008年度销售总金额
统计2008年度某类商品的销售总金额
统计2008年度某大类商品的销售总金额
product表中
产品ID 单价 存库量 类别ID
1 2.3 200 1
2 1.5 400 1
3 3 300 1
4 40 100 2
5 200 150 3

category表中
类别ID 类别名
1 饮料
2 计算机耗材
3 日用品

1、统计2008年度销售总金额:
select sum(b.单价*a.数量) from p_order a,product b where a.产品ID=b.产品ID and to_char(a.订货日期,'yyyy')='2008';

统计2008年度某类商品的销售总金额:
select sum(b.单价*a.数量) from p_order a,product b where a.产品ID=b.产品ID and to_char(a.订货日期,'yyyy')='2008' and 产品ID=某类;

统计2008年度某大类商品的销售总金额:
select sum(b.单价*a.数量) from p_order a,product b where a.产品ID=b.产品ID and to_char(a.订货日期,'yyyy')='2008' and 产品ID=大某类;

统计2008年度销售总金额:
select sum(o.amount*p.price) sumprice from p_order o,product p where o.order_date between to_date('2008-1-1','yyyy-mm-dd') and to_date('2008-12-31','yyyy-mm-dd') and o.product_id=p.product_id
统计2008年度某类商品的销售总金额 :
select sum(o.amount*p.price) sumprice from p_order o,product p where o.order_date between to_date('2008-1-1','yyyy-mm-dd') and to_date('2008-12-31','yyyy-mm-dd') and o.product_id=p.product_id and p.product_id