MSSQL SYNTAX需要转换为MYSQL

时间:2013-01-28 11:35:10

标签: mysql sql-server-2008

我有以下Microsoft sql server查询,我想在MYSQL DAtabase上运行。

在mysql数据库上获得以下错误:

  

[Err] 1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在'[Incident Num]附近使用正确的语法,tt.name作为[Ticket Type],freetext2作为[Severity],tp.name作为[Pri'在第1行

我使用的Microsoft Sql server查询:

SELECT t.tn AS [Incident Num],
       tt.name as [Ticket Type],
       freetext2 as [Severity],
       tp.name as [Priority] ts.name as [Status],
       title as [Description],
       create_time as [Created Timestamp],
       CASE WHEN th.state_id=15 THEN
       (select min(th.create_time) FROM ticket_history GROUP BY th.ticket_id,
           th.state_id having th.state_id=15  ) else create_time as [Assigned to Accenture Timestamp],
       (select min(create_time) FROM ticket_history group by ticket_id,state_id having state_id=4) as [In Progress Timestamp],
       (select min(create_time) FROM ticket_history group by ticket_id,state_id having state_id=3)as [Restored timestamp],
       (select max(create_time) FROM ticket_history group by ticket_id,state_id having state_id=2)as [Closed Timestamp],
       (select DATEDIFF(mi,max(create_time,min(create_time) FROM ticket_history group by ticket_id,state_id having state_id=12) as [Total Time spent by the ticket in 'Pending at user'status],
       cu.email as [Customer Name],
       customer_user.email AS Assignee
FROM ticket t
JOIN ticket_type tt ON t.type_id=tt.id
JOIN ticket_Priority tp ON t.ticket_priority_id=tp.id
JOIN ticket_state ts ON t.ticket_state_id=ts.id
JOIN ticket_history th ON t.id=th.ticket_id
JOIN customer_user cu ON t.customer_id=cu.customer_id
JOIN customer_user ON t.responsible_user_id=customer_user.id

请帮我修改查询语法为** MySQL **而不更改逻辑。

1 个答案:

答案 0 :(得分:1)

当您定义自定义列标题时,请将它们放在引号内(或者在反引号中,如下所示:

t.tn AS '[Incident Num]', // and so on

OR

t.tn AS `[Incident Num]`, // and so on

错误是因为同样的原因。