mysql数据库查询语句

mysql数据库查询语句-每日运维

mysql查看某个数据库中所有表(即有哪些表)的语句是什么呀?谢谢!!

SHOW TABLES


mysql数据库sql查询语句:多条件判断

1、创建测试表,

create table test_person(id int, RMB int);

mysql数据库查询语句-每日运维

2、插入测试数据

insert into test_person values(1,180);

insert into test_person values(2,170);

insert into test_person values(3,290);

insert into test_person values(4,160);

insert into test_person values(5,299);

insert into test_person values(6,266);

insert into test_person values(7,155);

mysql数据库查询语句-每日运维

3、查询表中所有记录,select t.* from test_person t,

mysql数据库查询语句-每日运维

4、编写sql,汇总每个vip类型的用户数,

select vip_type, count(distinct id)

from (select case when RMB>100 and RMB<200 then 'VIP1' when RMB>200 then 'VIP2' end as vip_type, id

from test_person) t

group by vip_type

mysql数据库查询语句-每日运维


如何提高mysql数据库查询语句

首先分析为什么慢:1. 6个子查询,每个子查询都需要建立中间表湖装必;2,每个子查询都在做 group by, 重复;3 CA来自SE WHEN 用不了索引,需要扫描所有列; 优化:CASE WHEN 逻辑合并,6个子查询合并为1个查询,做1次 group by,做 join,