如何按问题运行SQL查询组? [英] How to run SQL query group by issue?
本文介绍了如何按问题运行SQL查询组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有列的表:
表名称:IdentityTable
Table Name: IdentityTable
ID Dest_Name Dest_Reference_Id Format IG
31231231 India Delhi XKHYGUI 21
12313131 USA Washington XHKOWKG 1
34645542 India Mumbai XKLWOFH 1
31231314 USA California XLGJDJG 21
31234531 India Delhi XKHIHUI 21
12375671 USA Washington XHKLHKG 21
12574613 USA Washington XLKWMKG 1
以此类推...
我想查询此表以这种形式检索信息:
I want to query this table to retrieve information in this form:
Dest_Name Dest_Reference_Id Total_Format Format IG
India Delhi 2 XKHYGUI 21
India Delhi 2 XKHIHUI 21
USA Washington 3 XHKOWKG 1
USA Washington 3 XHKLHKG 21
USA Washington 3 XLKWMKG 1
India Mumbai 1 XKLWOFH 1
USA California 1 XLGJDJG 21
我做到了:
select dest_name, dest_reference_id, count (format)
from IdentityTable
Group By dest_name, dest_reference_id;
我可以检索结果中除格式"列之外的所有必需信息.我应该如何修改查询以返回预期结果?
I could retrieve all information required except Format column in the result. How should I modify my query to return expected result ?
推荐答案
count(*) over(partition by dest_name, dest_reference_id)
,且没有group by
. google"oracle解析函数".
and without a group by
. google "oracle analytic functions".
这篇关于如何按问题运行SQL查询组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文