最近在面试的时候常见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;
网友评论