1.用一条SQL 语句 查询出每门课都大于80 分的学生姓名
name kecheng fenshu
张三 语文 81
张三 数学 75
李四 语文 76
李四 数学 90
王五 语文 81
王五 数学 100
王五 英语 90
select name from table group by name having min(fenshu)>80
select distinct name from table where name not in(select distinct name from table where fenshu<80)
2.查询出来10-20条之间的数据
select top 10 *from table Id >(select max(Id) from(select top 10 Id from table order by Id ASC) as Tmpdata) order by Id Asc
3. 学生表 如下:
自动编号 学号 姓名 课程编号 课程名称 分数
1 2005001 张三 0001 数学 69
2 2005002 李四 0001 数学 89
3 2005001 张三 0001 数学 69
删除除了自动编号不同, 其他都相同的学生冗余信息
delete from table where Id not in(select min(Id) from table group by SId,name,Curs,CurNAme.Score)
4.写SQL语句,求出2018年各个省份购物花费最多的人的姓名
现有:
商品表(Id,商品名,价格)
客户表(Id,姓名,手机号,省份)
订单表(Id,商品Id,客户Id,购买时间,购买渠道)
select *from a inner join b on a.Id=b.Id inner join c on c.Id=b.Id group by 省份 having max(money)
5.表结构和数据
date result
2011-02-01 胜
2011-02-01 负
2011-02-01 胜
2011-02-02 胜
2011-02-02 负
查询出来的结果:
date 胜 负
2011-02-01 2 1
2011-02-02 1 1
思路:第一步先根据时间进行分组查询,查出来当前时间胜的次数再查询出来当前时间负的次数
select date,(select count(*) from table where date=t.date and result='胜') as '胜' ,(select count(*) from table where date=t.date and result='负') as '负' from table as t group by date