高级sql
查询某班级男女数量
查询某班级大于平均分小于平均分的数量
查询某租户下在线离线网元
···sql
drop view if exists v_res_ne_customer_count;
CREATE ALGORITHM=UNDEFINED DEFINER=root
@localhost
SQL SECURITY DEFINER VIEW v_res_ne_customer_count
AS
SELECT
t_res_customer
.id
AS custmer_id
,
t_res_customer
.name
AS customer_name
,
sum(case when t_res_ne
.state
=1 then 1 else 0 end) up,
sum(case when t_res_ne
.state
=0 then 1 else 0 end) down
FROM
(((
t_res_customer
LEFT JOIN t_res_customer_ne
ON ((
t_res_customer_ne
.customer_id
= t_res_customer
.id
)))
LEFT JOIN t_res_ne
ON ((
t_res_ne
.id
= t_res_customer_ne
.ne_id
))) )
GROUP BY t_res_customer
.id
···