LeetCode题解(1364):顾客的可信联系人数量(SQL)
发布日期:2021-06-29 20:11:59
浏览次数:2
分类:技术文章
本文共 811 字,大约阅读时间需要 2 分钟。
题目:(中等)
标签:SQL
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|---|---|---|
Ans 1 (Python) | 1162ms (11.60%) | ||
Ans 2 (Python) | |||
Ans 3 (Python) |
解法一:
SELECT I.invoice_id, C.customer_name, I.price, IFNULL(U1.contacts_cnt, 0) AS contacts_cnt, IFNULL(U2.trusted_contacts_cnt, 0) AS trusted_contacts_cntFROM Invoices AS I LEFT JOIN Customers AS C ON I.user_id = C.customer_id LEFT JOIN (SELECT user_id, contact_name AS customer_name, COUNT(contact_name) AS contacts_cnt FROM Contacts GROUP BY user_id) AS U1 ON I.user_id = U1.user_id LEFT JOIN (SELECT user_id, COUNT(contact_name) AS trusted_contacts_cnt FROM Contacts WHERE contact_email IN (SELECT email FROM Customers) GROUP BY user_id) AS U2 ON I.user_id = U2.user_idORDER BY I.invoice_id;
转载地址:https://dataartist.blog.csdn.net/article/details/110421387 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月03日 22时40分00秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
python中时间日期相减并转化为秒
2019-04-30
django中迁移表失败怎么办
2019-04-30
python在得到绝对路径时候 \ 转化/
2019-04-30
python中二维码得生成
2019-04-30
Odoo 14 初级入门学习
2019-04-30
python drf 小程序 微信支付 退款 逻辑加代码
2019-04-30
odoo14 rpc 链接报错 容易出错怎样解决
2019-04-30
python os 怎样使用 读取一个文件中所有图片的名称
2019-04-30
python 图片转化为base64
2019-04-30
小程序支付 xml拼接 和生成 sign签名 代码
2019-04-30
python pandas excle 把两列合并新的一列
2019-04-30
odoo 中 tree中的字段隐藏 排序等
2019-04-30
有道翻译 爬虫 讲解 和 代码
2019-04-30
python中 .py 文件打包成 .exe可执行文件
2019-04-30
Ubuntu 安装虚拟环境 安装python 3.7配置等
2021-07-03
【使用技巧】VS2017避免全部安装至C盘
2021-07-03