SKY外语计算机学习

标题: 写sql语句怎么实现下列查询 [打印本页]

作者: CODE    时间: 2013-6-18 11:56
标题: 写sql语句怎么实现下列查询
(表)t
a b(列)
1 2
1 3
1 4
2 1
2 2
3 1
4 1
5 3
5 2
查询结果要求
a b
1 2
2 1
3 1
4 1
5 2
作者: testnew    时间: 2013-6-18 13:00
先看看,等待高手来解答
作者: 骏马    时间: 2013-6-18 13:07
SELECT * FROM t GROUP BY a
作者: testnew    时间: 2013-6-18 13:23
上面这个不行吧
作者: 耒匚伱    时间: 2013-6-18 13:29
select a,min(b) from t group by a
作者: CANDY    时间: 2013-6-18 13:36
select a,min(b) as b from t group by a
作者: Kill    时间: 2013-6-18 13:46
candy和她楼上两位写得很好
作者: rogan    时间: 2013-6-18 15:14
来个不一样的
CREATE TABLE sky(
w text,
j text);
insert into sky VALUES (1,2);
insert into sky VALUES (1,3);
insert into sky VALUES (1,4);
insert into sky VALUES (2,1);
insert into sky VALUES (2,2);
insert into sky VALUES (3,1);
insert into sky VALUES (4,1);
insert into sky VALUES (5,3);
insert into sky VALUES (5,2);

select s.w, (select min(j) from sky where w = s.w) from (select DISTINCT w as w from sky) s;
作者: CODE    时间: 2013-6-18 19:29

楼上几位写得很好,都是牛人啊,谢谢大家
作者: SKY精英    时间: 2013-8-15 15:25
select a,count(b) from t group by a
作者: 857401199    时间: 2015-3-14 10:47





欢迎光临 SKY外语计算机学习 (http://www.skywj.com/) Powered by Discuz! X2.5