gpt4 book ai didi

mysql - 将 3 个查询优化为一个查询的最佳方法

转载 作者:行者123 更新时间:2023-11-29 03:52:37 27 4
gpt4 key购买 nike

假设我有以下查询。

SELECT count(*) FROM info WHERE info = 'a' and uid = 1
SELECT count(*) FROM info WHERE info = 'b' and uid = 1
SELECT count(*) FROM info WHERE info = 'c' and uid = 1;

有什么方法可以在一个查询中获取所有这些详细信息,而不是编写 3 个查询?

最佳答案

SELECT info, count(*) as info_cnt 
FROM T
WHERE uid = 1 and info IN ('a', 'b','c')
GROUP BY info

关于mysql - 将 3 个查询优化为一个查询的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14438815/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com