使用下面的查詢,我可以搜索給定半徑內的屬性並返回結果。MySQL - 在指定HAVING時使用COUNT()返回總計結果
SELECT id, address, (3959 * acos(cos(radians(53.184815)) * cos(radians(lat)) * cos(radians(lng) - radians(-3.025741)) + sin(radians(53.184815)) * sin(radians(lat)))) AS distance
FROM properties
WHERE area = 1 HAVING distance <= 1
ORDER BY price DESC, distance ASC
LIMIT 0, 10
但是我現在想添加分頁,因此「LIMIT 0,10」但不知何故讓查詢返回的總成績。例如,如果有100個結果,但我們僅限於前10個結果,則返回總數爲100.
我試着在select後添加「COUNT(*)AS total」,但是這導致了零結果被退回。
如何讓查詢以這種方式返回總數?
SQL_CALC_FOUND_ROWS和SELECT FOUND_ROWS();之後; – splash58
SQL_CALC_FOUND_ROWS顯然最多慢10倍:http://stackoverflow.com/questions/186588/which-is-fastest-select-sql-calc-found-rows-from-table-or-select-count – Reado
total means ,行數或總屬性爲數字? – Avishake