计算下面特定行的行数

时间:2013-03-06 10:48:03

标签: mysql

这是我的表

enter image description here

如何编写查询,我想从ID = 2开始选择行数(或者可以是我输入的任何其他数字),但仅限于IDveterinar = 5或我输入的其他数字

SELECT COUNT(*) AS count FROM mytable...

这样的想法

3 个答案:

答案 0 :(得分:2)

SELECT 
    COUNT(*) AS count FROM mytable
WHERE 
    ID >= 2
    AND IDveterinar = 5

答案 1 :(得分:2)

SELECT COUNT(*) AS count FROM mytable WHERE id>=2 AND IDveterinar=5;

答案 2 :(得分:2)

如果要选择从ID 2(包括)开始的行数,则这是查询:

SELECT COUNT(*) AS count
FROM myTable
WHERE ID >= 2 AND IDveterinar = 5;

如果要选择从ID 2(不包括)开始的行数,则这是查询:

SELECT COUNT(*) AS count
FROM myTable
WHERE ID > 2 AND IDveterinar = 5;