我在MySQL中有两个查询
select count(activity_id) from asd where ico_detail_id = '5a673c68a895200d64cd6a18' and activity_id = 1 and is_active = 1;
select count(activity_id) from asd where ico_detail_id = '5a673c68a895200d64cd6a18' and activity_id = 2 and is_active = 1;
我想使用该过程或其他方法一次运行这两个查询。
需要帮助。 Thanxx in adv
答案 0 :(得分:1)
使用条件聚合,
SELECT SUM(CASE WHEN activity_id = 1 THEN 1 ELSE 0 END) activity_id_1,
SUM(CASE WHEN activity_id = 2 THEN 1 ELSE 0 END) activity_id_2
FROM bulltoken.ico_vote
WHERE ico_detail_id = '5a673c68a895200d64cd6a18'
AND is_active = 1;
这将显示:
---------------+---------------
activity_id_1 + activity_id_2
---------------+---------------
10 + 20
---------------+---------------
答案 1 :(得分:1)
select count(activity_id) from bulltoken.ico_vote where ico_detail_id = '5a673c68a895200d64cd6a18' and activity_id = 1 and is_active = 1;
UNION
select count(activity_id) from bulltoken.ico_vote where ico_detail_id = '5a673c68a895200d64cd6a18' and activity_id = 2 and is_active = 1;