mysql 索引 建立索引(a,b,c) 书上说a,b,c a,b a 这三种情况才使用索引

mysql 索引 建立索引(a,b,c) 书上说a,b,c a,b a 这三种情况才使用索引,第1张

书上说的也不是一定对的 针对a,b,c 这三个字段的组合索引 书上说 根据最左前缀原则 只有a a,b a,b,c 才能使用到索引 后来根据我亲自测试 得出 a,c 也是可以使用在这个组合索引 在网上看了很多人的答案 大部分都是根据书上说的原则的回答 但是往往实时就是出乎我们的意料之外

你是批量插入重复的b,c字段,a字段使用a表ID字段吗?

INSERT INTO b表(a,b,c)

SELECT id,'你要插入的B字段','你要插入的c字段' FROM a表

select agentid,sum(good) as good,sum(normal) as normal,sum(bad) as bad

from

(select agentid,1 as good,0 as normal,0 as bad

from A where content=1

union all

select agentid,0 as good,1 as normal,0 as bad

from A where content=2

union all

select agentid,0 as good,0 as normal,1 as bad

from A where content=3

)B

group by agentid


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/7173322.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-02
下一篇 2023-04-02

发表评论

登录后才能评论

评论列表(0条)

保存