我想分组我的查询,以便我的结果只显示一次每个帐号。下面是我正在使用的SQL。在SQL中分组查询和子查询项目
`select top 10 c.svc, sum(c.tx_amt) as "Total Payments", d.fyear_name, d.fmonth_name, c.acctnbr_int,
(select iif(datediff("d",c.svc_dte,c.pst_dte)<=6 and c.trans_cd in ('0092001','0092051','0093201','0093204','0093212','0093601','0093652','0093653','0093654','0093655','0093701','0096316','0096351','0096366',
'0096405','0096407','0096408','0096409','0096422','0096452','0096455','0096456','0096459','0096473','0096474','0091551'),sum(c.tx_amt),0)) as "POS Payments"
from rptg.vwall_chg_tx_plus c
join rptg.vwdim_date d on c.pst_dte = d.day_date
where c.Pst_Dte > '09/30/2015' and c.Pst_Dte < '11/1/2015'
and c.Svc = '002'
and c.pt_acct_ctg_nme <> 'inpatient'
and c.trans_cd in ('0093101','0093102','0093151','0093152','0093251','0096302','0096303','0096304','0096305','0096306','0096307','0096308','0096309','0096311','0096312',
'0096313','0096314','0096322','0096343','0096352','0096353','0096354','0096355','0096356','0096357','0096358','0096359','0096361','0096362','0096363','0096364','0096367',
'0096372','0096375','0096380','0096381','0096382','0096383','0096392','0096398','0096399','0096426','0096454','0096458','0096477','0096478','0098353','0098354','0098400',
'0098401','0092001','0092051','0093201','0093204','0093212','0093601','0093652','0093653','0093654','0093655','0093701','0096316','0096351','0096366','0096405','0096407',
'0096408','0096409','0096422','0096452','0096455','0096456','0096459','0096473','0096474','0091551','0093254','0093272','0093751','0096395','0096406','0096410','0096412',
'0096413','0096451','0096457','0096472','0099201')
and c.AcctNbr_int in ('3215385349')`
结果是: SVC总支出fyear_name fmonth_name acctnbr_int POS支付 002 -150.00 FY 2016 FY16 M4 3215385349 -150.00 002 -100.00 FY 2016 FY16 M4 3215385349 -100.00
但结果应该是: SVC POS光电倍增管总的光电倍增管FYear_name fmonth_name AcctNbr_int Insrnc_Pyr_Cde 002($ 250.00)($ 250.00)FY 2016 FY16 M4 3215385349 SELF PAY
当我尝试组的项目和金额(c.tx_amt)我收到关于group by子句中不允许的聚合或子查询的错误消息。
谢谢