How to ORDER BY with different columns as one column?

后端 未结 2 345
温柔的废话
温柔的废话 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

提交回复
热议问题