MYSQL到MS SQL查询转换

时间:2017-11-15 09:36:56

标签: mysql sql sql-server

我有MySQL查询。我想在MS SQL Server中执行此查询。 如何将MySQL转换为MS SQL。

SELECT  DST.name AS name,
        BWT.name AS name,
        FOD.name AS name,   
        GROUP_CONCAT(ODH.name SEPARATOR ';') as name, 
FROM DST 
LEFT join BWT 
    on DST.name = BWT.name 
LEFT join firstorderdata as FOD 
    on DST.name = FOD.name 
LEFT join ODH 
    on DST.name = ODH.name 
WHERE DST.dist_status != 'T' 
group by DST.name

如果可能的话,我还希望为此查询结果生成csv

如果有人知道请帮助我......

1 个答案:

答案 0 :(得分:1)

SQL Server 2017开始,您可以使用STRING_AGG

SELECT  DST.name AS name,
        BWT.name AS name,
        FOD.name AS name,   
        STRING_AGG(ODH.name, ';') as name    --changed
FROM DST 
LEFT join BWT 
    on DST.name = BWT.name 
LEFT join firstorderdata as FOD 
    on DST.name = FOD.name 
LEFT join ODH 
    on DST.name = ODH.name 
WHERE DST.dist_status != 'T' 
group by DST.name AS name,
        BWT.name AS name,    -- added
        FOD.name AS name;    -- added

列应具有独特的别名:

SELECT  DST.name AS d_name,
        BWT.name AS b_name,
        FOD.name AS f_name,