将select zdlx,qyxx.* from t_sjzx_wryzxjc_qyxx qyxx left join ( select entername,string_agg(lb, ',') zdlx from ( select entername, string_agg(lb||'重点', ',') lb from t_sjzx_zdpwdwml GROUP BY entername UNION all select devcompany entername,'排污许可重点管理' lb from t_hbb_pwdwjbxx where management='重点管理' GROUP BY devcompany ) zdml GROUP BY entername ) zdml on qyxx.qymc = zdml.entername改成MySQL语句
时间: 2024-03-17 13:47:39 浏览: 301
将SQL Server语句转换为MySQL语句,需要将`STRING_AGG`函数替换为`GROUP_CONCAT`函数,并且将子查询中的列别名移动到子查询外部,如下所示:
```
SELECT qyxx.*, zdml.zdlx
FROM t_sjzx_wryzxjc_qyxx qyxx
LEFT JOIN (
SELECT entername, GROUP_CONCAT(lb, ',') AS zdlx
FROM (
SELECT entername, GROUP_CONCAT(lb||'重点', ',') AS lb
FROM t_sjzx_zdpwdwml
GROUP BY entername
UNION ALL
SELECT devcompany AS entername, '排污许可重点管理' AS lb
FROM t_hbb_pwdwjbxx
WHERE management='重点管理'
GROUP BY devcompany
) AS zdml
GROUP BY entername
) AS zdml ON qyxx.qymc = zdml.entername;
```
这条MySQL语句与原始SQL Server语句的功能相同,可以查询`t_sjzx_wryzxjc_qyxx`表和`SELECT entername, GROUP_CONCAT(lb||'重点', ',') AS lb FROM t_sjzx_zdpwdwml GROUP BY entername UNION ALL SELECT devcompany AS entername, '排污许可重点管理' AS lb FROM t_hbb_pwdwjbxx WHERE management='重点管理' GROUP BY devcompany`子查询的结果集,并将它们按照`qymc`和`entername`列进行左连接。
阅读全文