SQL查询语句如下:
select vbak.ordnum, custpo=case when rtrim(ltrim(isnull(vbak.refnm1,'')))='' then 'c/o'else vbak.refnm1 end, isnull(vbak.cusnam,'') as cusnam,isnull(vbak.cusad1,'') as cusad1, isnull(vbak.cusad2,'') as cusad2,isnull(vbak.cusad3,'') as cusad3, isnull(vbak.cusad4,'')+' ' + isnull(vbak.cusad5,'') as cusadd, isnull(vbak.cusad6,'') as cusad6,zipcod = case when isnull(cusad7,'')<>'' then '*'+cusad7+'*' else '' end, loat.scacid,cast.caseno, joit.pallid,joit.climat,count(joit.climat) as palqty from loat inner join cast on loat.loadid=cast.loadid inner join joit on cast.caseno = joit.caseno inner join vbak on joit.ordnum = vbak.ordnum
where cast.loadid = 'E00007' and joit.pallid between '01' and '01'
group by vbak.ordnum,vbak.refnm1,vbak.cusnam,vbak.cusad1,vbak.cusad2, vbak.cusad3,vbak.cusad6,vbak.cusad4,vbak.cusad5,vbak.cusad7, loat.scacid,cast.caseno,joit.pallid,joit.climat
order by cast(joit.pallid as int) 但是在Query中执行时,group之前的语句不能正常执行提示错误
Msg 8120, Level 16, State 1, Line 1
Column 'vbak.ORDNUM' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
但是加上group by后面的语句就会正常执行
请高手们执教,这是什么原因,谢谢!
select vbak.ordnum, custpo=case when rtrim(ltrim(isnull(vbak.refnm1,'')))='' then 'c/o'else vbak.refnm1 end, isnull(vbak.cusnam,'') as cusnam,isnull(vbak.cusad1,'') as cusad1, isnull(vbak.cusad2,'') as cusad2,isnull(vbak.cusad3,'') as cusad3, isnull(vbak.cusad4,'')+' ' + isnull(vbak.cusad5,'') as cusadd, isnull(vbak.cusad6,'') as cusad6,zipcod = case when isnull(cusad7,'')<>'' then '*'+cusad7+'*' else '' end, loat.scacid,cast.caseno, joit.pallid,joit.climat,count(joit.climat) as palqty from loat inner join cast on loat.loadid=cast.loadid inner join joit on cast.caseno = joit.caseno inner join vbak on joit.ordnum = vbak.ordnum
where cast.loadid = 'E00007' and joit.pallid between '01' and '01'
group by vbak.ordnum,vbak.refnm1,vbak.cusnam,vbak.cusad1,vbak.cusad2, vbak.cusad3,vbak.cusad6,vbak.cusad4,vbak.cusad5,vbak.cusad7, loat.scacid,cast.caseno,joit.pallid,joit.climat
order by cast(joit.pallid as int) 但是在Query中执行时,group之前的语句不能正常执行提示错误
Msg 8120, Level 16, State 1, Line 1
Column 'vbak.ORDNUM' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
但是加上group by后面的语句就会正常执行
请高手们执教,这是什么原因,谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货