How to ORDER BY with different columns as one column?

后端 未结 2 346
温柔的废话
温柔的废话 2021-01-26 03:08

I\'ve got the following code below:

$db = $this->database[GDB];
$num_rows = $db->doQuery(\'SELECT TOP 100 strUserId, TotalTime, Nation, LoginDT FROM USERDA         


        
相关标签:
2条回答
  • 2021-01-26 03:50

    You can change your query to this

    $num_rows = $db->doQuery('SELECT TOP 100 strUserId, TotalTime, Nation, LoginDT FROM USERDATA WHERE Authority IN(1, 2) ORDER BY (TotalTime + ('.time().' + 7200 - LoginDT)) DESC');
    

    Please note that the query is concatenated with time() since it's a PHP function, not a SQL Server function.

    This is the generated query

    SELECT TOP 100 strUserId, TotalTime, Nation, LoginDT FROM USERDATA WHERE Authority IN(1, 2) ORDER BY (TotalTime + (1416132847 + 7200 - LoginDT)) DESC
    

    Demo: http://codepad.org/vSR2FJ8C

    0 讨论(0)
  • 2021-01-26 03:56

    Have you tried

    SELECT TOP 100 strUserId, TotalTime + (time() + 7200 - LoginDT) as
    newTotalTime, Nation, LoginDT FROM USERDATA WHERE Authority IN(1, 2)
    ORDER BY newTotalTime DESC
    
    0 讨论(0)
提交回复
热议问题