SQL笔试
--Basic facts gathering
--1.
--按每辆单车的使用用户数排序,没有被使用的次数none排在最后
SELECT b.id, t.u_num
FROM bikes b
LEFT JOIN (
SELECT bike_id, COUNT(DISTINCT user_id) AS u_num
FROM trips
WHERE started_at >= '2017-06-01'
AND completed_at <= '2017-06-30'
AND status = 'completed'
GROUP BY bike_id
) t
ON b.id = t.bike_id
ORDER BY t.u_num DESC
--按每辆单车的trip次数排序,没有trip的none排在最后
SELECT b.id, t.num
FROM bikes b
LEFT JOIN (
SELECT bike_id, COUNT(1) AS num
FROM trips
WHERE star
SQL笔试最先出现在Python成神之路。
共有 0 条评论