我正在使用MySql,我有一种情况,我想从表返回所有行的计数,并通过在同一查询中使用限制返回一些行。我尝试了很多东西,但我无法做到。请帮帮我
假设我的表是:学生
id | name | category | gender
1 'A' 'Just' 'male'
2 'B' 'Just' 'Female'
3 'C' 'Just' 'male'
4 'D' 'Just' 'Female'
5 'E' 'Just' 'male'
输出:
id | name | category | gender | rcount
1 'A' 'Just' 'male' 5
2 'B' 'Just' 'Female' 5
3 'C' 'Just' 'male' 5
我希望单个查询的上述输出请帮帮我?
答案 0 :(得分:0)
@Krishna在下面找到查询:
select SQL_CALC_FOUND_ROWS *, (select count(*) from student) as rcount from student limit 3;
答案 1 :(得分:-1)
/*
create table student (id int, name char(2), category char(4), gender char(6));
insert into student values
(1 , 'A' , 'Just' , 'male'),
(2 , 'B' , 'Just' , 'Female'),
(3 , 'C' , 'Just' , 'male'),
(4 , 'D' , 'Just' , 'Female'),
(5 , 'E' , 'Just' , 'male');
*/
select *,(select count(*) from student) as rcount
from student
limit 3