1

这是我现有的 SQL 语句:

SELECT TOP 10 Users.FirstName + ' ' + Users.LastName AS Name,
              Feeds.LogType,
              Feeds.LogDesc,
              Feeds.Timestamp = DATEDIFF(MINUTE, Feeds.Timestamp, CURRENT_TIMESTAMP)
FROM Feeds
INNER JOIN Users ON Feeds.UserID = Users.UserID
ORDER BY Feeds.Timestamp DESC

我在第二行有错误,Incorrect syntax near '='.

任何想法如何解决这一问题?

4

4 回答 4

4

尝试

SELECT TOP 10 Users.FirstName + ' ' + Users.LastName AS NAME
    ,Feeds.LogType
    ,Feeds.LogDesc
    ,DATEDIFF(MINUTE, Feeds.TIMESTAMP, CURRENT_TIMESTAMP)
FROM Feeds
INNER JOIN Users ON Feeds.UserID = Users.UserID
ORDER BY DATEDIFF(MINUTE, Feeds.TIMESTAMP, CURRENT_TIMESTAMP) DESC
于 2013-04-18T16:23:20.647 回答
1

Feeds.Timestamp = DATEDIFF(MINUTE, Feeds.Timestamp, CURRENT_TIMESTAMP) should be

DATEDIFF(MINUTE, Feeds.Timestamp, CURRENT_TIMESTAMP) AS Timestamp 
于 2013-04-18T16:25:16.170 回答
1

而不是 = 尝试别名为,

SELECT TOP 10 Users.FirstName + ' ' + Users.LastName AS Name, Feeds.LogType,
    Feeds.LogDesc,
    DATEDIFF(MINUTE, Feeds.Timestamp, CURRENT_TIMESTAMP) [Timestamp]
FROM Feeds INNER JOIN Users ON Feeds.UserID = Users.UserID
ORDER BY Feeds.Timestamp DESC
于 2013-04-18T16:26:29.143 回答
1

您可以以“alias = value”的方式使用别名,但您不应该指定表名,所以

Timestamp = DATEDIFF(MINUTE, Feeds.Timestamp, CURRENT_TIMESTAMP)
于 2013-04-19T08:42:29.280 回答