我需要一个sql select查询,用以下scenerio来检索数据。 [英] I need a sql select query, to retreive data with below scenerio.
问题描述
GroupId GeneralId名称
3 10000 aaaaa
3 10000 bbbbb
3 10000 ccccc
3 10000 ddddd
2 50000 eeeee
2 50000 fffff
2 50000 ggggg
2 50000 hhhhh
1 跨度> 10000 aaaaa
1 10000 bbbbb
1 10000 ccccc
1 10000 ddddd
我想要一般id的最大GroupId
预期输出为
GroupId
3
2
我尝试了以下查询,但我没有得到输出
1 。 从 tbl = code-string> 3',< span class =code-string>' 2')GroupId分组
2 跨度>。 选择 GroupId 来自 tbl 其中 GeneralId 中的class =code-keyword>(' 3',' 2')GroupId分组,GroupId = MAX(GroupId)
请告诉我查询。
对不起,我上面的查询不是相关的,我试过了
1.选择MAX(GroupId)来自tbl,其中GeneralId in('50000','10000')Group by GroupId
2.从tbl中选择GroupId,其中GeneralId in('50000','10000')Group by GroupId拥有GroupId = MAX(GroupId)
我输出如下
GroupID
1
2
3
尝试:
SELECT MAX(GroupID)
FROM tbl
GROUP BY GeneralId
GroupId GeneralId name
3 10000 aaaaa
3 10000 bbbbb
3 10000 ccccc
3 10000 ddddd
2 50000 eeeee
2 50000 fffff
2 50000 ggggg
2 50000 hhhhh
1 10000 aaaaa
1 10000 bbbbb
1 10000 ccccc
1 10000 ddddd
I want general id's max GroupId
Expected output is
GroupId
3
2
I tried below queries, but i did not get output
1. select MAX(GroupId) from tbl where GeneralId in ('3','2') Group by GroupId
2. select GroupId from tbl where GeneralId in ('3','2') Group by GroupId having GroupId=MAX(GroupId)
Please tell me the query.
Sorry, the query what i put above was not correcr,i tried
1. select MAX(GroupId) from tbl where GeneralId in ('50000','10000') Group by GroupId
2. select GroupId from tbl where GeneralId in ('50000','10000') Group by GroupId having GroupId=MAX(GroupId)
but i got output as below
GroupID
1
2
3
Try:
SELECT MAX(GroupID) FROM tbl GROUP BY GeneralId
这篇关于我需要一个sql select查询,用以下scenerio来检索数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!