• 1571. 仓库经理


    表: Products

    +---------------+---------+
    | Column Name | Type |
    +---------------+---------+
    | product_id | int |
    | product_name | varchar |
    | Width | int |
    | Length | int |
    | Height | int |
    +---------------+---------+
    product_id 是该表主键.
    该表的行包含了每件商品以英尺为单位的尺寸(宽度, 长度和高度)信息.
     

    写一个 SQL 查询来报告, 每个仓库的存货量是多少立方英尺.

    仓库名
    存货量
    返回结果没有顺序要求.

    查询结果如下例所示.

    Warehouse 表:
    +------------+--------------+-------------+
    | name | product_id | units |
    +------------+--------------+-------------+
    | LCHouse1 | 1 | 1 |
    | LCHouse1 | 2 | 10 |
    | LCHouse1 | 3 | 5 |
    | LCHouse2 | 1 | 2 |
    | LCHouse2 | 2 | 2 |
    | LCHouse3 | 4 | 1 |
    +------------+--------------+-------------+

    Products 表:
    +------------+--------------+------------+----------+-----------+
    | product_id | product_name | Width | Length | Height |
    +------------+--------------+------------+----------+-----------+
    | 1 | LC-TV | 5 | 50 | 40 |
    | 2 | LC-KeyChain | 5 | 5 | 5 |
    | 3 | LC-Phone | 2 | 10 | 10 |
    | 4 | LC-T-Shirt | 4 | 10 | 20 |
    +------------+--------------+------------+----------+-----------+

    Result 表:
    +----------------+------------+
    | warehouse_name | volume |
    +----------------+------------+
    | LCHouse1 | 12250 |
    | LCHouse2 | 20250 |
    | LCHouse3 | 800 |
    +----------------+------------+

    解题方案:

    select `name` as warehouse_name, sum(voc) as volume from (SELECT `name`, units*Width*`Length`*`Height` as voc 
    from Warehouse a
    left join Products b
    using(product_id)) as c
    group by `name`
  • 相关阅读:
    删除commit(暂存区)中的文件(git)
    bower安装使用以及git安装
    compass模块----Utilities----Sprites精灵图合图
    compass模块----Utilities
    compass模块----Helpers
    compass模块
    compass安装
    Sass@规则
    Sass函数--颜色函数--Opacity函数
    Sass函数--颜色函数--HSL函数
  • 原文地址:https://www.cnblogs.com/tomorrow-hope/p/13834417.html
Copyright © 2020-2023  润新知