1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > mysql group where_[MySQL] 测试where group by order by的索引问题

mysql group where_[MySQL] 测试where group by order by的索引问题

时间:2021-08-11 09:44:48

相关推荐

mysql group where_[MySQL] 测试where group by order by的索引问题

1. select * from test where a=xx group by b order by c 如何加索引

CREATE TABLE `index_test` (

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

`name` varchar(100) NOT NULL DEFAULT '',

`gid` int(11) NOT NULL DEFAULT '0',

`age` int(11) NOT NULL DEFAULT '0',

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

MysqL> select * from index_test;

+----+------------+-----+

| id | name | gid |

+----+------------+-----+

| 1 | taoshihan | 2 |

| 2 | taoshihan1 | 2 |

+----+------------+-----+

2. 加个联合索引试试

alter table index_test add index name_gid_age_index(name,gid,age);

explain select * from index_test where name='taoshihan' group by gid order by age;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。