我有这样的查询结果 http://i.imgur.com/9m7P3mX.png
编辑:这是实际表 http://pastebin.com/TZCGHKdt
第二次编辑: http ://sqlfiddle.com/#!2/49bae/1
如果您在 SQLFIDDLE 链接中看到结果,它会在 ID 列中显示重复的条目。例如 ID 列中的值 26 共有 4 个值,查询显示它们分为 3 和 1。我希望它们加入。
这是我正在使用的表的插入查询
INSERT INTO `capture_captive` (`capture_id_1`, `capture_id_2`, `capture_id_3`, `capture_id_4`, `capture_id_5`)
VALUES
(23, 32, 0, 0, 0),
(26, 25, 24, 0, 15),
(26, 32, 0, 0, 0),
(0, 0, 0, 0, 0),
(26, 26, 0, 0, 0),
(32, 32, 0, 0, 0);
我正在使用的查询是
select id, num from
(select `capture_id_1` id, (COUNT(capture_id_1)) num from capture_captive where capture_id_1<>0 group by capture_id_1
UNION
select `capture_id_2`, (COUNT(capture_id_2)) num from capture_captive where capture_id_2<>0 group by capture_id_2
UNION
select `capture_id_3`, (COUNT(capture_id_3)) num from capture_captive where capture_id_3<>0 group by capture_id_3
UNION
select `capture_id_4`, (COUNT(capture_id_4)) num from capture_captive where capture_id_4<>0 group by capture_id_4
UNION
select `capture_id_5`, (COUNT(capture_id_5)) num from capture_captive where capture_id_5<>0 group by capture_id_5 ) as E
where id<>0
order by id;
我想根据他们的 id 显示 id 的总数。
提前致谢。