sql - GROUP BY shows the same group more than once when using CASE -
i'm having issue case
statement in t-sql
here query:
select case when cri.chartretrievalmethodid null wfseg.siteeventgroupid else cri.chartretrievalmethodid end type, count(distinct c.chartid) totalcharts sites s left bring together charts c on s.siteid=c.siteid left bring together chartretrievalinformation cri on c.chartid=cri.chartid left bring together wfsiteevents wfse on wfse.siteid=s.siteid left bring together wfsiteeventtypes wfset on wfset.eventtypeid=wfse.eventtypeid left bring together wfsiteeventgroups wfseg on wfset.siteeventgroupid=wfseg.siteeventgroupid wfse.eventstatusid in (1,2) , s.projectid=110 grouping cri.chartretrievalmethodid, wfseg.siteeventgroupid
i'm getting lot of multiple rows instead of them combining 1 - example:
+------+--------------+ | type | total charts | +------+--------------+ | 3 | 28 | | 3 | 3 | +------+--------------+
ideally these 2 rows mashed one:
+------+--------------+ | type | total charts | +------+--------------+ | 3 | 31 | +------+--------------+
i'm sure there nil i'm writing incorrectly can't seem see is.
if include fields cri.chartretrievalmethodid, wfseg.siteeventgroupid
in column list select statement, become clear why these shown in multiple rows grouping.
what want grouping value you're calling type
. in dbms simple group type
, in sql server must repeat total look in group by
clause.
sql tsql group-by case
No comments:
Post a Comment