赞
踩
- create table tableA
- (
- name varchar(10),
- kecheng varchar(10),
- fenshu int(11)
- )DEFAULT CHARSET = 'utf8';
- insert into tableA values ('张三','语⽂',81);
- insert into tableA values ('张三','数学',75);
- insert into tableA values ('李四','语⽂',76);
- insert into tableA values ('李四','数学',90);
- insert into tableA values ('王五','语⽂',81);
- insert into tableA values ('王五','数学',100);
- insert into tableA values ('王五','英语',90);
- 答案A:
- select distinct name from tableA where name not in (select distinct name fr
- om tableA where fenshu<=80)
-
- 答案B:
- select name from tableA group by name having min(fenshu)>80
-
- 答案C:
- select name from tableA group by name having count(kecheng)>=3 and min(fens
- hu)>=80
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要⽣成下列结果, 该如何写sql语句?
- create table tableb (
- rq varchar(10),
- shengfu nchar(1)
- )DEFAULT CHARSET = 'utf8';
- insert into tableb values('2005-05-09','胜');
- insert into tableb values('2005-05-09','胜');
- insert into tableb values('2005-05-09','负');
- insert into tableb values('2005-05-09','负');
- insert into tableb values('2005-05-10','胜');
- insert into tableb values('2005-05-10','负');
- insert into tableb values('2005-05-10','负')
- select rq, sum(case when shengfu='胜' then 1 else 0 end)'胜',sum(case when
- shengfu='负' then 1 else 0 end)'负' from tableb group by rq
- CREATE TABLE team (
- `name` varchar(20)
- ) DEFAULT CHARSET=utf8;
- INSERT INTO team VALUES ('a');
- INSERT INTO team VALUES ('b');
- INSERT INTO team VALUES
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。