[Code]Sql选择字段唯一值并上后面的字段
需求: 选择A字段唯一值,并上B字段,如果A字段相同B字段不同,则取第一次出现的B字段的值。
表
A B Id
--------------------------------------
1 A 1
1 B 2
2 C 3
2 D 4
3 E 5
3 F 6
选择结果:
A B Id
--------------------------------------
1 A 1
2 C 3
3 E 5
表
A B Id
--------------------------------------
1 A 1
1 B 2
2 C 3
2 D 4
3 E 5
3 F 6
选择结果:
A B Id
--------------------------------------
1 A 1
2 C 3
3 E 5
SELECT *
FROM TEST
WHERE (ID IN
(SELECT MIN(id)
FROM TEST
GROUP BY A))
3 Comments:
白痴都不更新么
This paragraph will help the internet people for setting up new website or even a blog from start to end.
I absolutely love your blog and find almost all of your post's to be exactly I'm looking for. Do you offer guest writers to write content to suit your needs? I wouldn't mind writing a post or elaborating on a lot of the subjects you write related to here. Again, awesome site!
Post a Comment
<< Home