通过进一步检查对

时间:2017-03-07 15:20:52

标签: php mysql mysqli

目前,我正在获得以下结果:

SELECT Progress, COUNT(*) AS counter
FROM finished
GROUP BY Progress

然后显示结果如下:

if($row['Progress'] == '0') {
    echo $row['counter'];
}
if($row['Progress'] == '1') {
    if (($row['date_sent'] !== '0000-00-00 00:00:00') && ($row['notes'] !== '0')) {
        echo $row['counter'];
    } else if ($row['date_sent'] !== '0000-00-00 00:00:00') {
        echo $row['counter'];
    }
}

但是我想在可能的情况下对这些数字进行分组,因此如果某些内容的进度值为1,则发送日期=" 0000-00-00 00:00:00"和notes = 1,然后它计算那些行,它还计算具有0个音符的行。

这可能吗?

我需要的是计算

SELECT * FROM finished WHERE Progress=1 date_sent = '0000-00-00 00:00:00' AND notes = 0

然后计算

SELECT * FROM finished WHERE Progress=1 date_sent = '0000-00-00 00:00:00' AND notes != 0

以及计算Progress = 0,Progress = 2和Progress = 3,尽管此时不需要2/3。

编辑以显示我正在尝试的内容:

SELECT Progress, 
    (SELECT COUNT(id) FROM finished WHERE date_sent is NULL AND notes = 0) as firstcount,
    (SELECT COUNT(id) FROM finished WHERE date_sent is NULL) as secondcount
FROM finished
GROUP BY Progress

此外,如果没有备注,但进度为1,则无需计算。

0 个答案:

没有答案