常见面试题之数据库查询
2019-03-15 本文已影响0人
向上十五度
最近在面试的时候常见SQL题目:
1、统计胜负结果的SQL语句
期望结果:
查询出的结果具体实现SQL:
具体SQL:
SELECT
date,
(
SELECT
count(*)
FROM
table1
WHERE
date = t.date
AND result = '胜'
) AS '胜',
(
SELECT
count(*)
FROM
table1
WHERE
date = t.date
AND result = '负'
) AS '负'
FROM
table1 AS t
GROUP BY
date;