将mssql查询转换为mysql查询

时间:2011-08-13 02:17:18

标签: mysql sql-server

我在网上找到了以下mssql查询,该查询应该可以帮助我解决我几天来一直在努力解决的复杂mysql查询问题。

SELECT
    inv.typeID AS typeID,
    inv.typeName AS typeName,
    invGroups.groupName AS groupName,
    inv.published AS published,
    inv.description AS description,
    rankVal.valueFloat AS rank,
    replace (( SELECT skills.attributeName AS [data()]
      FROM dgmTypeAttributes tattr  -- Link between skillbook and attributes
      INNER JOIN dgmAttributeTypes skills ON (skills.attributeID = tattr.valueInt)
      WHERE (tattr.typeID = inv.typeID)
        AND (tattr.attributeID IN (180, 181)) -- Primary and secondary attributes
      ORDER BY inv.typeID FOR xml path('')), ' ', ',') AS prisec,
    replace (( SELECT RTRIM(CAST(inv2.typeID AS varchar)) + ',' AS [data()]
      FROM (SELECT * FROM dgmTypeAttributes WHERE (attributeID in (182, 183, 184)) -- Pre-req skills 1, 2, and 3
        AND (typeID = inv.typeID)) tattr2 
      INNER JOIN invTypes inv2 ON (tattr2.valueInt = inv2.typeID)
      ORDER BY inv.typeID FOR xml path('')), ' ', ' ') AS prereq,
    replace (( SELECT RTRIM(CAST(tattr2.valueInt AS varchar)) + ',' AS [data()]
      FROM (SELECT * FROM dgmTypeAttributes WHERE (attributeID in (277, 278, 279)) AND (typeID = inv.typeID)) tattr2  -- Link between skillbook and attributes
      ORDER BY inv.typeID FOR xml path('')), ' ', ' ') AS prereqlvl
FROM invTypes inv
INNER JOIN invGroups ON (inv.groupID = invGroups.groupID)
INNER JOIN dgmTypeAttributes rankVal ON (inv.typeID = rankVal.typeID)
WHERE invGroups.categoryID = 16 -- Skillbooks category    
    AND rankVal.attributeID = 275 -- Skill rank attribute
    AND inv.published = 1
GROUP BY inv.typeID, inv.typeName, invGroups.groupName, inv.published, inv.description, rankVal.valueFloat
ORDER BY invGroups.groupName, inv.typeName

我是如此使用mysql但我对mssql一无所知。有人可以推荐一种很好的方法来转换这个低或现在成本的查询吗?我不希望有人为我转换它,因为这会要求太多,但一些建议会指向我在仪式方向(除了学习mssql lolz)将是非常好的。感谢您的时间和耐心。

2 个答案:

答案 0 :(得分:0)

'建议:使用utf8(unicode)字符集在分隔文件(csv)中从MySQL数据库中提取数据。使用bcp指定utf8并使用“-Jutf8”参数和字符模式“-c”导入SQL Server。请参阅this网站。此外,还有一个很好的tool

答案 1 :(得分:0)

那些FOR XML PATH('')的子查询似乎用于连接字符串1。看看你是否可以用MySQL中的GROUP_CONCAT替换它们。其他位似乎是标准SQL。