使用mysql数据库,在帆软10报表设计器中写SQL数据集报错。失去了数据集描写如下:
SELECT sum(b_amount) as hz,pf_xh,ylbm,yl_name,b_amount FROM `t_gybl_bom`
where bl_date='${dateEditor0}' and hz <> b_amount
group by ylbm
系统报错:unknown column ‘hz’in 'where clause'
SQL语法不对;
=========
根据题意,SQL可以换个思路:
SELECT sum(b_amount) AS hz, pf_xh, ylbm, yl_name FROM t_gybl_bom WHERE bl_date = '${dateEditor0}' and b_amount != 0 and b_amount is not null GROUP BY pf_xh, ylbm, yl_name HAVING count(*) > 1
两处问题,where中不能用自定义字段名hz,group by需要计算字段外所有字段,修改如下
where bl_date='${dateEditor0}'
group by pf_xh,ylbm,yl_name,b_amount
having sum(b_amount)<> b_amount
不说别的 SQL中 如果有聚合函数 sum() max() min() count() 等 其他字段必须出现在GROUP BY 后面,再说在说
按我理解的意思 你要的应该是 sum(b_amount)over(parition by ylbm) 那样的效果,是吗
你这SQL语法就不对,没有这种写法的