帮忙看看 这三句mysql能不能写成一句?

SELECT COUNT(*) AS tp_count FROM `qra_works` WHERE `created_time` > '2023-05-10 18:44:37' LIMIT 1 
SELECT COUNT(*) AS tp_count FROM `qra_works` WHERE `created_time` > '2023-05-10 18:44:37' AND `version` = 'junior' LIMIT 1 
SELECT COUNT(*) AS tp_count FROM `qra_works` WHERE `created_time` > '2023-05-10 18:44:37' AND `version` = 'senior' LIMIT 1 

帮忙看看 这三句mysql能不能写成一句?
感觉执行3次影响效率,不知道为什么写成一句,该怎么写?

阅读 1.9k
3 个回答
✓ 已被采纳
SELECT 
    version, COUNT(*) AS tp_count 
FROM 
    `qra_works` 
WHERE 
    `created_time` > '2023-05-10 18:44:37' 

group by version
SELECT 
    COUNT(*) AS total_count,
    SUM(CASE WHEN version = 'junior' THEN 1 ELSE 0 END) AS junior_count,
    SUM(CASE WHEN version = 'senior' THEN 1 ELSE 0 END) AS senior_count
FROM 
    qra_works
WHERE 
    created_time > '2023-05-10 18:44:37'
SELECT 
    COUNT(*) AS tp_count 
FROM 
    `qra_works` 
WHERE 
    `created_time` > '2023-05-10 18:44:37' 
    OR (`created_time` > '2023-05-10 18:44:37' AND `version` = 'junior') 
    OR (`created_time` > '2023-05-10 18:44:37' AND `version` = 'senior')
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏