sql查询练习

1、有以表结构如下

id  goodsid  scount  type

6     3            40     out

5     2            30     in

4     1            45     out

3     3            20     out

2     2            20     in

1     1            10     in

要查询到如下结果
goodsid 进货 出库 库存

解:

select  goodsid,sum(a.sin) as aa,sum(a.sout) as bb ,sum(a.sin)-sum(a.sout)
from
(select id,goodsid, case type when 'in' then scount else '0' end as sin,case type when 'out' then scount else '0' end as sout
from test2) as a
group by a.goodsid

 

2、有表结构如下

name  result type

 张三   95     语文
 张三   85     数学
 张三   87     英语
 李四   67     数学
 李四   85     英语
 王五   86     语文
 王五   78     数学

要求查询出所有学科成绩都再80以上的学生名单

解:

select distinct(name)
from test3
where name not in(
  select NAME
  from test3
  where result<80
  )


 

 

转载于:https://www.cnblogs.com/yidianfeng/archive/2011/11/04/2236305.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值