在求一个SQL语句

a12321321321312321 2010-12-06 02:45:39

id(主键自增) Time count
1 2010-12-01 1
2 2010-12-01 1
3 2010-12-02 1
4 2010-12-02 2
5 2010-12-03 2
6 2010-12-04 3


我要取出每个count字段的第一条记录。。如取出的结果为
1 2010-12-01 1
4 2010-12-02 2
6 2010-12-04 3
...全文
106 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
a12321321321312321 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wufeng4552 的回复:]
最近赚分难啊
[/Quote]
呵呵你都这么多红花了,还在乎这点分。。刚刚加了100分,给大家,谢谢大家咯。
a12321321321312321 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 josy 的回复:]
引用 4 楼 f800051235 的回复:
引用 2 楼 josy 的回复:
SQL code
select *
from tb t
where id=(select min(id) from tb where [count]=t.[count])

帅哥你这个好像有点问题。。


什么问题,贴出来看看
[/Quote]
不好意思刚刚试了下,我弄错了,你的方法没问题。。。
a12321321321312321 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 guguda2008 的回复:]
引用 3 楼 beirut 的回复:

SQL code

--1
select * from tb a
where not exists( select 1 from tb where [count]=t.[count] and id<t.id)

--2
select * from tb a where id=(select id from tb where [count]=……
[/Quote]
小爱的方法是有问题,呵呵,但是人家这么热心回复我还是要感谢人家嘛。
wufengye12 2010-12-06
  • 打赏
  • 举报
回复
水族杰纶 2010-12-06
  • 打赏
  • 举报
回复
最近赚分难啊
黄_瓜 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 guguda2008 的回复:]
引用 3 楼 beirut 的回复:

SQL code

--1
select * from tb a
where not exists( select 1 from tb where [count]=t.[count] and id<t.id)

--2
select * from tb a where id=(select id from tb where [count]=……
[/Quote]
百年树人 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 f800051235 的回复:]
引用 2 楼 josy 的回复:
SQL code
select *
from tb t
where id=(select min(id) from tb where [count]=t.[count])

帅哥你这个好像有点问题。。
[/Quote]

什么问题,贴出来看看
guguda2008 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 beirut 的回复:]

SQL code

--1
select * from tb a
where not exists( select 1 from tb where [count]=t.[count] and id<t.id)

--2
select * from tb a where id=(select id from tb where [count]=t.[count])
[/Quote]
小爱秀逗了,LZ别管他
hualanlan 2010-12-06
  • 打赏
  • 举报
回复
呵呵,新人来学习下
a12321321321312321 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 josy 的回复:]
SQL code
select *
from tb t
where id=(select min(id) from tb where [count]=t.[count])
[/Quote]
帅哥你这个好像有点问题。。
黄_瓜 2010-12-06
  • 打赏
  • 举报
回复

--1
select * from tb a
where not exists( select 1 from tb where [count]=t.[count] and id<t.id)

--2
select * from tb a where id=(select id from tb where [count]=t.[count])

百年树人 2010-12-06
  • 打赏
  • 举报
回复
select *
from tb t
where id=(select min(id) from tb where [count]=t.[count])
guguda2008 2010-12-06
  • 打赏
  • 举报
回复
SELECT *
FROM TB T1
WHERE NOT EXISTS(
SELECT 1 FROM TB T2 WHERE T2.COUNT=T1.COUNT AND T2.ID<T1.ID
)

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧