SELECT *
FROM numbers_for_fun
WHERE
(a = 0 AND b = 0 AND c <= 0)
OR
(a = 0 AND b > 0 AND c <= 0)
OR
(a < 0 AND (
(b >= 0 AND c <= 0) OR
(b < 0 AND b*b <= 4*a*c)
))
ORDER BY a, b, c;
select name, subject, class_code, qualification
from teachers
where (fir_degr = '北京大学' or fir_degr = '清华大学') and head_teacher is not null
order by name asc
SELECT *
FROM numbers_for_fun
WHERE
(a = 0 AND (
(b = 0 AND c < 0) OR
(b > 0 AND c < 0) OR
(b < 0)
))
OR
(a > 0 AND (
(c < 0) OR
(c >= 0 AND b < 0 AND b*b > 4*a*c)
))
OR
(a < 0);
select exam_date,
max(case when subject = '语文' then score end) as chinese_score,
max(case when subject = '数学' then score end) as math_score,
max(case when subject = '英语' then score end) as english_score
from scores
where student_id = '460093'
group by exam_date
with user_login_days as(
select
usr_id,
date(login_time) as login_date
from
user_login_log
where
login_time >= date_sub(curdate(), interval 180 DAY)
),
distinct_login_days as(
select
usr_id,
count(distinct login_date) as login_days
from
user_login_days
group by
usr_id
)
select
sum(case when 1<= login_days and login_days <= 5 then 1 else 0 end) as days_1_to_5,
sum(case when 6<= login_days and login_days <= 10 then 1 else 0 end) as days_6_to_10,
sum(case when 11<= login_days and login_days <= 20 then 1 else 0 end) as days_11_to_20,
sum(case when login_days > 20 then 1 else 0 end) as days_over_20
from
distinct_login_days
with user_login_days as(
select
usr_id,
date(login_time) as login_date
from
user_login_log
where
login_time >= date_sub(curdate(), interval 180 DAY)
),
distinct_login_days as(
select
usr_id,
count(distinct login_date) as login_days
from
user_login_days
group by
usr_id
)
select
sum(case when login_days between 1 and 5 then 1 else 0 end) as days_1_to_5,
sum(case when login_days between 6 and 10 then 1 else 0 end) as days_6_to_10,
sum(case when login_days between 11 and 20 then 1 else 0 end) as days_11_to_20,
sum(case when login_days > 20 then 1 else 0 end) as days_over_20
from
distinct_login_days
with user_login_days as(
select
usr_id,
date(login_time) as login_date
from
user_login_log
where
login_time >= date_sub(curdate(), interval 180 DAY)
),
distinct_login_days as(
select
usr_id,
count(distinct login_date) as login_days
from
user_login_days
group by
usr_id
)
select
sum(case when login_days between 1 and 5 then 1 else 0 end) as days_1_to_5,
sum(case when login_days between 1 and 5 then 1 else 0 end) as days_6_to_10,
sum(case when login_days between 1 and 5 then 1 else 0 end) as days_11_to_20,
sum(case when login_days between 1 and 5 then 1 else 0 end) as days_over_20
from
distinct_login_days
with user_login_days as(
select
usr_id,
date(login_time) as login_date
from
user_login_log
where
login_time >= date_sub(curdate(), interval 180 DAY)
),
distinct_login_days as(
select
usr_id,
count(distinct login_date) as login_days
from
user_login_days
group by
usr_id
)
select
sum(case when 1< login_days <= 5 then 1 else 0 end) as days_1_to_5,
sum(case when 6< login_days <= 10 then 1 else 0 end) as days_6_to_10,
sum(case when 11< login_days <= 20 then 1 else 0 end) as days_11_to_20,
sum(case when login_days > 20 then 1 else 0 end) as days_over_20
from
distinct_login_days
with user_login_days as(
select
usr_id,
date(login_time) as login_date
from
user_login_log
where
login_time >= date_sub(curdate(), interval 180 DAY)
),
distinct_login_days as(
select
usr_id,
count(distinct login_date) as login_days
from
user_login_days
group by
usr_id
)
select
sum(case when 1<= login_days <= 5 then 1 else 0 end) as days_1_to_5,
sum(case when 6<= login_days <= 10 then 1 else 0 end) as days_6_to_10,
sum(case when 11<= login_days <= 20 then 1 else 0 end) as days_11_to_20,
sum(case when login_days > 20 then 1 else 0 end) as days_over_20
from
distinct_login_days
select
count(distinct case
when time(login_time) between '07:30:00' and '09:30:00'
or time(login_time) between '18:30:00' and '20:30:00' then usr_id end) as commute,
count(distinct case
when time(login_time) between '11:30:00' and '14:00:00' then usr_id end) as lunch_break,
count(distinct case
when time(login_time) between '22:30:00' and '23:59:59' then usr_id
when time(login_time) between '00:00:00' and '01:00:00' then usr_id end) as bedtime
from user_login_log
where
login_time >= date_format(date_sub(curdate(), interval 1 month), '%Y-%m-01')
and login_time < date_format(curdate(), '%Y-%m-01')