(22)sql server 里的sql 语句错误(66分)

  • 主题发起人 主题发起人 千中元
  • 开始时间 开始时间

千中元

Unregistered / Unconfirmed
GUEST, unregistred user!
select gcmc,gcxm,nf,yf,bysm,byq,byqt,byt,bydl,bygjg,
sum(bysm) smh, sum(byq) qh,sum(byqt) qth,sum(byt) th,
sum(bydl) dlh,sum(bygjg) gjgh
from detail
where gcmc=:gcmc and gcxm=:gcxm and (nf<:nf or (nf=:nf and yf<:yf))
在用field editor 增加字段的时候,出现如下错误:
General SQL error:
Column 'detail.gcmc' is invalid in the select list
because it's not contained and aggregate function
and there is no group by?
该怎么改呢?

 
你的sql语法写错了,如果sql语句中含有sum那么那些不含sum的字段必须在
sql语句后面用group by,因为sql语句求和时必须知道对哪些值求和,按照什么
标准求和,
正确的语法应该是:
select gcmc,gcxm,nf,yf,bysm,byq,byqt,byt,bydl,bygjg,
sum(bysm) smh, sum(byq) qh,sum(byqt) qth,sum(byt) th,
sum(bydl) dlh,sum(bygjg) gjghfrom detail
where gcmc=:gcmc and gcxm=:gcxm and (nf<:nf or (nf=:nf and yf<:yf))
group by gcmc,gcxm,nf,yf,bysm,byq.....
如果有问题可以mailto:xueminliu@263.net
 
后退
顶部