将CTE转换为MySQL兼容查询

时间:2014-07-24 23:14:28

标签: mysql

这是我的架构

enter image description here

这是我的查询结果

enter image description here

我如何删除重复项,只是突出显示值,我正在尝试按消息时间排序

With some Help

WITH CTE AS
(
    SELECT c.ContactID, c.Name, m.Text, m.Messagetime,
           RN = ROW_NUMBER() OVER (PARTITION BY c.ContactID
                                   ORDER BY m.MessageTime DESC)
    FROM dbo.Contacts c
    INNER JOIN Messages m ON c.ContactID = m.ContactID
)
SELECT ContactId, Name, Text, Messagetime
FROM CTE
WHERE RN = 1 order by messagetime

我设法获得了预期的结果,但我怎样才能将其转换为在mysql上运行

此致

0 个答案:

没有答案