通过(简单)放置SQL顺序

时间:2016-12-08 12:59:44

标签: php sql sql-order-by sql-limit

我试图在参考时订购以下结果。使用Order by和desc limit 100.有人可以帮助我放置它。

$stm = $pdo->prepare("SELECT `reference`, SUM( `stockdifference` ) AS 'stockdifference'  
FROM `results1` 
WHERE `datum` BETWEEN '".$oldDate."' AND '".$newDate."' AND `reference` = '".$stm[0]."'");

2 个答案:

答案 0 :(得分:0)

订购SQL查询很简单。

Select *
FROM table
Where column=condition
ORDER BY column desc/asc
Limit

答案 1 :(得分:-1)

尝试:

<?php 
$stm = $pdo->prepare("SELECT `reference`, SUM( `stockdifference` ) AS 'stockdifference'  
FROM `results1` 
WHERE `datum` BETWEEN '".$oldDate."' AND '".$newDate."' AND `reference` = '".$stm[0]."'
Order by 'your column',
'your column' desc,
limit 100

");