首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
›
MySQL 5.5 Community Server
›
MySQL 5.6 Community Server
›
Percona Configuration Wizard
›
XtraBackup 搭建主从复制
Great Sites on MySQL
›
Percona
›
MySQL Performance Blog
›
Severalnines
推荐管理工具
›
Sequel Pro
›
phpMyAdmin
推荐书目
›
MySQL Cookbook
MySQL 相关项目
›
MariaDB
›
Drizzle
参考文档
›
http://mysql-python.sourceforge.net/MySQLdb.html
广告
V2EX
›
MySQL
count 的语句优化问题
supersf
·
8 小时 47 分钟前
· 309 次点击
最近在 mysql 中做了一个查询
select count(*) from
(select a,b,count(distinct c) from table group by a,b having count(distinct c)>=2) as t
把 mysql 库跑死掉了
请教下有什么可以优化的空间?
目前想到的是下面
select count(*) from
(select a,b from table group by a,b having count(distinct c)>=2) as t
count
优化
查询
1 条回复
1
supersf
OP
8 小时 31 分钟前 via iPhone
Gemini 反馈可以用 min 和 max SELECT
count(*)
FROM
(
SELECT
a,
b
FROM
table
GROUP BY
a,
b
HAVING
min(c) <> max(c)
) AS t;
关于
·
帮助文档
·
自助推广系统
·
博客
·
API
·
FAQ
·
实用小工具
·
977 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 24ms ·
UTC 19:49
·
PVG 03:49
·
LAX 12:49
·
JFK 15:49
Developed with
CodeLauncher
♥ Do have faith in what you're doing.
❯