select
y.stdname as zzjg,
n.stdname as km,
sum(t.DZXWXYS) as dzxys,
sum(t.RCWXYS) as rccbys
from WXYSMXN_FD as t
left join MD_ORG as y on t.unitid=y.recid
left join WXYSKM as n on t.wxyskm=n.recid
where y.recid = @unitid
and m.recid = @department
group by t.WXYSKM
可以参考官方文档的教程:
https://eco.dameng.com/docs/zh-cn/sql-dev/practice-single-table.html
你这个语法不符合sql标准,MYSQL8.0默认都不支持你这个写法了。
group by WXYSKM这一个字段,输出结果会是一个WXYSKM作为一行,然后y.stdname和n.stdname随机取一条,这样会可能出现每次查询结果不一样的情况,不严谨。
查询的非聚合字段,一定是要放到group by 后面去的,否则应该使用any_value或者max、min函数按指定规则取一个值。
经测试,达梦可开启兼容MySQL的模式,这样就可以使用上述group by语句了