按查询返回组所需的行数

时间:2013-11-11 13:45:25

标签: mysql sql select group-by

我想从使用number of rows的mysql查询中返回group by。 表

CREATE TABLE IF NOT EXISTS TestRunSteps (
`idTestRunSteps` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`idUsersExecBy` VARCHAR(10) NULL ,
`LastExecUserIPV4` INT UNSIGNED NULL ,
PRIMARY KEY (`idTestRunSteps`);

SELECT count(*)
from proj1_db.TestRunSteps
group by idUsersExecBy,LastExecUserIPV4

返回

 3,000002,3232236222 
 1,000003,3232236222 
 5,000004,3232236222 

我想要的是一个简单的3 - 3行。请告诉我如何

2 个答案:

答案 0 :(得分:1)

组数是按组分组的不同组合的数量。返回该数字的查询是:

select count(distinct idUsersExecBy, LastExecUserIPV4)
from proj1_db.TestRunSteps

答案 1 :(得分:0)

select count(*)
from
(SELECT count(*)
from proj1_db.TestRunSteps
group by idUsersExecBy,LastExecUserIPV4) as temp