如何编写SQL查询以达到预期的效果。 [英] How to write SQL query to achieve desired result.
问题描述
我的数据如下
type id no
g 61 0
t 48 5 >
t 140 13
t 146 13
i想要输出如下
类型ID否
g 61 0
t 48 5
t 140 13
我尝试了什么:
i尝试使用子查询,但由于中间列有所有独特的记录。
请尽快提供解决方案
谢谢
i have data as follows
type id no
g 61 0
t 48 5
t 140 13
t 146 13
i want output as follows
type id no
g 61 0
t 48 5
t 140 13
What I have tried:
i tried using sub queries but dint work since middle column is having all unique records.
please provide the solution as soon as possible
Thanks
推荐答案
猜测 - 如果您给我们的信息有限,那么您希望按类型和编号进行分组,并返回最低的ID值:
At a guess - and given the limited info you give us that's all it can be - you want to group by type and number, and return the lowest ID value:
SELECT [type], MIN(ID) AS id, no FROM MyTable GROUP BY [type], no
如果不是那,你需要更准确地解释你想要做什么。
If it isn't that, you need to explain in a lot more detail exactly what you are trying to do.
这篇关于如何编写SQL查询以达到预期的效果。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!