可能重複:
Fastest way to count exact number of rows in a very large table?獲取的行數在MySQL
查詢什麼我用它來獲得具有共同規範的行數。
實施例:其中idpost = 3
可能重複:
Fastest way to count exact number of rows in a very large table?獲取的行數在MySQL
查詢什麼我用它來獲得具有共同規範的行數。
實施例:其中idpost = 3
learning SQL考慮的行數:
select count(*) from mytable where idpost=3
請不要鏈接到w3schools,更多信息請參閱[W3Fools](http://w3fools.com/) –
這是多麼糟糕!來自街道的隨機顛簸,寫一個HTML頁面! – JvdBerg
不完全隨機的顛簸,如果您訪問該頁面,您會注意到作者列表。 –
可以使用COUNT()
記錄here。
SELECT COUNT(1) FROM posts WHERE idpost = 3
謝謝你soo:D –
由於性能原因,如果表中存在很多字段,我會考慮使用COUNT(idpost)而不是*(全部) – dbf
這個鏈接問題的接受答案(具體到[標記:sql-server],而不是[tag:mysql])和['COUNT()']的手動條目(http://dev.mysql.com/doc//en/group-by-functions.html# function_count)明確說明COUNT(*)是完全有效的。 MySQL手冊指出:「如果SELECT從一個表中檢索,並且沒有其他列被檢索,並且沒有WHERE子句,* * COUNT(*)'被優化爲非常快速地返回*」 – eggyal
嘗試
SELECT
COUNT(*) as NumberRows
FROM
your_table_name_here
WHERE
idpost = 3
;
查詢看起來是這樣的:
SELECT count(*) FROM some_table WHERE (conditions);
在您的例子:在MySQL
SELECT count(*) FROM some_table WHERE idpost=3;
更多關於計數行:MySQL 5.6 Reference Manual: 3.3.4.8. Counting Rows
編輯:
如果你想知道,它計算所有行的方式更好(count(*)
或count(1)
),看到這一點:What is better in MYSQL count(*) or count(1)?。
select count(*)函數獲取滿足特定條件的行數 - 在where語句中定義該行數。
http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html - 讀到這裏的
可能重複[?最快的方法來計算一個非常大的錶行的確切人數(http://stackoverflow.com/questions/6069237/fastest-way-to-count - 在一個非常大的表中的行數)或[php:統計mysql中的行數?](http://stackoverflow.com/questions/7049153/count-the-number -of-rows-in-mysql) –