设为首页 加入收藏

TOP

第四章 数据查询2 (上机)(五)
2014-11-24 07:58:24 来源: 作者: 【 】 浏览:10
Tags:第四章 数据查询 上机
0%)
select emp_name ,salary ,case
when salary<40000 then salary*0.0
when salary between 40000 and 49999 then salary*0.05
when salary between 50000 and 59999 then salary*0.07
when salary >=60000 then salary*0.10
end price
from employee




-- 查询公司中所有姓名有三个字的员工信息
select * from employee where rtrim(emp_name) like '___'




-- 生成公司销售的明细表 要求表中需要表现的信息为(定单号,销售员姓名,销售产品,供伙商名称,销售金额)
select b.order_no,emp_name,prod_name,sup_name,toa_amt
from sale_item a right join sales b on a.order_no=b.order_no
join product c on c.prod_id = a.prod_id join supply d on d.sup_id = a.sup_id
join employee e on e.emp_no=b.sale_id




-- 在采购明细表中查询 同类产品在不同时间进货差价 超过200元的产品及供货商名称
select product.prod_name,s1.sup_name,a.unit_price,a.pur_date,s2.sup_name,b.unit_price,b.pur_date
from pur_item a join pur_item b on a.pur_no=b.pur_no and a.unit_price - b.unit_price>200
join supply s1 on s1.sup_id=a.sup_id join supply s2 on s1.sup_id=s2.sup_id
join product on product.prod_id=a.prod_id where a.pur_date>b.pur_date




-- 查询在同一天进入公司的员工信息
select * from employee a join employee b on a.date_hired=b.date_hired
where a.emp_no>b.emp_no




--查询公司所有客户在公司的定货情况
select * from sales
right join customer on sales.cus_id=customer.cus_id




-- 查询由公司女业务员所接回的定单
select emp_name,order_no,cus_id,sale_id,toa_amt,order_date,ship_date,invoice_no,o_static from sales a
join employee b on a.sale_id=b.emp_no
where b.sex='F'






-- 查询公司中姓名相同的员工并按照员工编号显示员工信息 ******
select * from employee a
join employee b on a.emp_name=b.emp_name
where a.emp_no order by a.emp_no






-- 查询公司中目前业绩还没有超过2万的业务员 ********
select emp_name from sales
left join employee on emp_no=sale_id
group by emp_name
having sum(toa_amt)<20000




select * from sales




-- 查询仓库中还没有销售过的产品信息
select * from stock a
left join sale_item c on c.prod_id=a.prod_id
where c.order_no is null


select * from sale_item
select * from product
select * from stock


-- 查询公司员工的平均年龄
select avg(datediff(yy,birthday,getdate()))'平均年龄'
from employee






-- 查询没有在公司订购产品的客户名单
select cus_name from customer a
left join sales b on a.cus_id=b.cus_id
where b.order_no is null


select * from customer
select * from sales




-- 按照供货商来统计公司的销售榜
select sup_name,isnull (sum(qty*unit_price),0) s from sale_item
right join supply on supply.sup_id=sale_item.sup_id
group by sup_name

order by s desc

====================================================================================

2013.12.02 晚


首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇第四章 数据查询1(上机) 下一篇postgresql常用命令

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)