所以我有一个有几列的表,我正在做一个GROUP BY
. 除了获取其他列之外,我还想在MIN()
另一列为NULL
. 这是我到目前为止所拥有的:
表列:
id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
table2_id INT(11) UNSIGNED NOT NULL,
iteration INT(11) UNSIGNED,
timestamp INT(11) UNSIGNED NOT NULL
SQL:
SELECT
table2_id,
COUNT(id) as total,
COUNT(iteration) as completed,
# I want the MIN(timestamp) but only when
# iteration IS NULL
MIN(timestamp) as next_incomplete
FROM
table1
GROUP BY
table2_id