zoukankan      html  css  js  c++  java
  • 1098. 小众书籍

    书籍表 Books:

    +----------------+---------+
    | Column Name | Type |
    +----------------+---------+
    | book_id | int |
    | name | varchar |
    | available_from | date |
    +----------------+---------+
    book_id 是这个表的主键。
    订单表 Orders:

    +----------------+---------+
    | Column Name | Type |
    +----------------+---------+
    | order_id | int |
    | book_id | int |
    | quantity | int |
    | dispatch_date | date |
    +----------------+---------+
    order_id 是这个表的主键。
    book_id 是 Books 表的外键。
     

    你需要写一段 SQL 命令,筛选出订单总量 少于10本 的 书籍 。

    注意:不考虑 上架(available from)距今 不满一个月 的书籍。并且 假设今天是 2019-06-23 。

    下面是样例输出结果:

    Books 表:
    +---------+--------------------+----------------+
    | book_id | name | available_from |
    +---------+--------------------+----------------+
    | 1 | "Kalila And Demna" | 2010-01-01 |
    | 2 | "28 Letters" | 2012-05-12 |
    | 3 | "The Hobbit" | 2019-06-10 |
    | 4 | "13 Reasons Why" | 2019-06-01 |
    | 5 | "The Hunger Games" | 2008-09-21 |
    +---------+--------------------+----------------+

    Orders 表:
    +----------+---------+----------+---------------+
    | order_id | book_id | quantity | dispatch_date |
    +----------+---------+----------+---------------+
    | 1 | 1 | 2 | 2018-07-26 |
    | 2 | 1 | 1 | 2018-11-05 |
    | 3 | 3 | 8 | 2019-06-11 |
    | 4 | 4 | 6 | 2019-06-05 |
    | 5 | 4 | 5 | 2019-06-20 |
    | 6 | 5 | 9 | 2009-02-02 |
    | 7 | 5 | 8 | 2010-04-13 |
    +----------+---------+----------+---------------+

    Result 表:
    +-----------+--------------------+
    | book_id | name |
    +-----------+--------------------+
    | 1 | "Kalila And Demna" |
    | 2 | "28 Letters" |
    | 5 | "The Hunger Games" |
    +-----------+--------------------+

    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/unpopular-books
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

    # Write your MySQL query statement below
    select b.book_id, b.name from 
    (select * from Books  where available_from<'2019-05-23') b left join 
    (select * from Orders where dispatch_date>'2018-06-23' ) o on b.book_id = o.book_id group by b.book_id, b.name having sum(ifnull(o.quantity,0)) < 10
  • 相关阅读:
    【Selenium-WebDriver问题点】chromeDriver和chrome浏览器版本之间的兼容性问题
    【Linux】【Jmeter】配置Jmeter服务器和运行Jmeter
    【Linux】【JDK】常用命令使用集和裸机配置JDK步骤。
    【Linux】使用ZStack私有云创建本地Linux服务器
    js基本数据类型和typeof
    Javascript 面向对象编程
    css3作3D旋转视频展示
    css3中的border-radius
    css3中做3D导航栏
    css3动画学习笔记
  • 原文地址:https://www.cnblogs.com/leeeee/p/11902043.html
Copyright © 2011-2022 走看看