SQL刷题-2

贫穷贵公子范下午上完英语困得要死,头疼依旧刷题,今天也是丢人的一天

长沙碗底挑面馆?长沙风味但是不辣,一个路过可以去试试但是不是很好吃的面馆

Leetcode597. 好友申请 I :总体通过率(简单)

select
round(
    ifnull(
    (select count(*) from (select distinct requester_id, accepter_id from request_accepted) as A)
    /
    (select count(*) from (select distinct sender_id, send_to_id from friend_request) as B),
    0)
, 2) as accept_rate
Leetcode602. 好友申请 II :谁有最多的好友(中等)

UNION all 去重

SELECT id,count(*) as num 
from 
(
SELECT requester_id as id ,accepter_id as fri from request_accepted 
UNION all
SELECT accepter_id  as id ,accepter_id as fri from request_accepted 
) _add
group by id
ORDER BY num desc 
limit 1
 

小备注:限制输入只能是0或1

CREATE table cinema2(
seat_id int,
free int ,
CHECK (free in  (0,1))
)

Leetcode603.连续空余座位(简单)

SELECT DISTINCT  C1.seat_id 
from cinema2 as c1 
join cinema2 as c2
on  c1.free=1 and c2.free=1
and  ABS(c1.seat_id-c2.seat_id)=1
ORDER BY seat_id

你可能感兴趣的:(SQL刷题-leetcode,leetcode,sql,数据分析)