这个查询是使用我的VB项目中使用的访问来编写的,我在哪里下订单,以便先按最高的CountOfStockID值排序?
SELECT
tblRented.StockID,
Count(tblRented.StockID) AS CountOfStockID,
tblStock.itemname, tblStock.FilmStar
FROM
tblStock
INNER JOIN
tblRented ON tblStock.StockID = tblRented.StockID
GROUP BY
tblRented.StockID, tblStock.itemname, tblStock.FilmStar
HAVING
(((Count(tblRented.StockID)) > 0))
答案 0 :(得分:0)
ORDER BY
和GROUP BY
子句之后使用 HAVING
子句:
试试这个:
SELECT tblRented.StockID, Count(tblRented.StockID) AS CountOfStockID, tblStock.itemname, tblStock.FilmStar
FROM tblStock INNER JOIN tblRented ON tblStock.StockID = tblRented.StockID
GROUP BY tblRented.StockID, tblStock.itemname, tblStock.FilmStar
HAVING (Count(tblRented.StockID))>0
ORDER BY Count(tblRented.StockID) DESC
订单的一个例子:
SELECT ID, Count(Mark) As TotalMark
FROM TableName
WHERE ID<> 1
GROUP BY ID
HAVING Count(Mark) >10
ORDER BY Count(Mark) DESC