代码应该给我排序后的表,如果值'isOnline'== 1则为'onlineTime',如果'isOnline'== 0则为onlineTime +格林尼治标准时间1970年1月1日午夜以来的毫秒数(isOnline为TINYINT,onlineTime是BIGINT)

SELECT * FROM onlinecountertable
ORDER BY
    CASE `isOnline`
        WHEN 0 THEN `onlineTime`
        WHEN 1 THEN (onlineTime + (ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000))
        ELSE `onlineTime`
    END
    DESC LIMIT 30


但是,如果我使用上面的查询,它会给我这个错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ELSE -1
    END)
    DESC LIMIT 30 LIMIT 0, 25' at line 6

最佳答案

取代这个

    WHEN 1 THEN (onlineTime + (ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000))


这样

    WHEN 1 THEN (onlineTime + ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000))


干杯;-)

10-06 10:57