获得多行计数

时间:2016-03-21 10:50:42

标签: php mysql pdo

这是我桌子的插图。

id    |  stocks  | colour
0156  |   in     |  red
5482  |  out     |  red
5488  |  out     | yellow

我需要获得3行计数。如何在查询中使用3种不同类型的COUNT值?

$sql="SELECT count(*) FROM tbl, 
        (SELECT count(*) FROM tbl WHERE stock = 'out'),
        (SELECT count(*) FROM tbl WHERE colour= 'yellow')";
$statement = $connect->prepare($sql);
$statement->execute();
$row = $statement->fetch(PDO::FETCH_NUM);
$val_tot = $row[0]; //? 

0 个答案:

没有答案