当前位置: 首页 > 知识库问答 >
问题:

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

濮泳
2023-05-18
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次影响效率,不知道为什么写成一句,该怎么写?

共有2个答案

茹正祥
2023-05-18
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')
曹疏珂
2023-05-18
SELECT 
    version, COUNT(*) AS tp_count 
FROM 
    `qra_works` 
WHERE 
    `created_time` > '2023-05-10 18:44:37' 

group by version
 类似资料: