3用SQL语句完成下列查询:
(1)列出产品订购数量超过1000的订单号。
select OID from Orders9527 where QTY>1000
(2)列出每个代理商经手的订单数和总的订金以及该代理商的编号,姓名
select Agent9527.AID,ANAME,count(OID)as 订单数, sum(DOLLARS)as 总订金 from Agent9527,
Orders9527 where Agent9527.AID=Orders9527.AID group by Agent9527.AID,ANAME
(3)找出同时通过代理商01和02购买产品的顾客编号,姓名。
4完成如下更新
将薪水不高于5000的代理商的薪水提高10%,高于5000的代理商的薪水提高5%.
update Agent9527 set SALARY=SALARY*1.05 where SALARY>5000
update Agent9527 set SALARY=SALARY*1.1 where SALARY<=5000
5使用游标完成如下操作:
使用游标找出经手办理的订单订金总额大于1000的代理商,将其薪水提高5%.
declare c1 cursor for
select Agent9527.AID,ANAME from Agent9527,Orders9527 where Agent9527.AID=Orders9527.AID
group by Agent9527.AID,ANAME having sum(DOLLARS)>1000
open c1
declare @x int
declare @y varchar(8)
fetch next from c1 into @x,@y
while @@fetch_status=0
begin
update Agent9527 set SALARY=SALARY*1.05 where SALARY=@x and ANAME=@y
fetch next from c1 into @x,@y
end
close c1
deallocate c1
6列出在通过代理商01购买产品数量最多的顾客的编号。
select Customer9527.CID from Customer9527 ,Orders9527 where Customer9527.CID=Orders9527.CID
and PID=01 group by Customer9527.CID having count(QTY)>=all(select count(QTY) from Orders9527 where PID=01
group by Orders9527.CID)