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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值