力扣sql基础篇(二)
1 每月交易I
1.1 题目内容
1.1.1 基本题目信息
1.1.2 示例输入输出
1.2 示例sql语句
SELECT DATE_FORMAT( trans_date, "%Y-%m" ) month , country, count ( * ) trans_count, COUNT ( IF ( state= "approved" , state, null ) ) approved_count,
sum ( amount) trans_total_amount, sum ( IF ( state= "approved" , amount, 0 ) ) approved_total_amount
FROM Transactions
GROUP BY country, month ;
1.3 运行截图
2 各赛事的用户注册率
2.1 题目内容
2.1.1 基本题目信息
2.1.2 示例输入输出
2.2 示例sql语句
SELECT contest_id, ROUND ( count ( user_id) / ( SELECT count ( user_id) FROM Users) * 100 , 2 ) percentage
FROM Register
GROUP BY contest_id
ORDER BY percentage desc , contest_id asc ;
2.3 运行截图
3 即时事物配送I
3.1 题目内容
3.1.1 基本题目信息
3.1.2 示例输入输出
3.2 示例sql语句
SELECT Round ( ( SELECT count ( delivery_id) FROM Delivery WHERE order_date= customer_pref_delivery_date) / count ( delivery_id) * 100 , 2 ) immediate_percentage
FROM Delivery
3.3 运行截图