mysql - 如何同时运行多个mysql查询

标签 mysql

我在 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;

我想使用过程或其他方式同时运行这两个查询。

需要帮助。感谢在广告中

最佳答案

使用条件聚合,

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          
---------------+---------------

关于mysql - 如何同时运行多个mysql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48679706/

相关文章:

mysql - IN 查询在 mysql 子查询中不起作用 group_concat

PHP-MySql : How to store and retrieve checkbox value with other option

mysql - 机器人筛选网站的每个页面

mysql - 带 where = false 的 rails scope,在 heroku 上的工作方式不同

sql - MySQL连接问题

php - mysql drupal 6 查询问题

php - 登录时禁止系统的问题

php - 如何使用 mysqli 在查询中按月份编号获取月份名称?

mysql - 计算不同的和重复的mysql

php - FPDF 创建运输标签