• 1068. 产品销售分析 I


    问题描述:

    销售表 Sales:

    +-------------+-------+
    | Column Name | Type |
    +-------------+-------+
    | sale_id | int |
    | product_id | int |
    | year | int |
    | quantity | int |
    | price | int |
    +-------------+-------+
    (sale_id, year) 是销售表 Sales 的主键.
    product_id 是关联到产品表 Product 的外键.
    注意: price 表示每单位价格
    产品表 Product:

    +--------------+---------+
    | Column Name | Type |
    +--------------+---------+
    | product_id | int |
    | product_name | varchar |
    +--------------+---------+
    product_id 是表的主键.
     

    写一条SQL 查询语句获取 Sales 表中所有产品对应的 产品名称 product_name 以及该产品的所有 售卖年份 year 和 价格 price 。

    解题答案:

    1.

    select b.product_name as product_name, `year`, price from Sales a
    left join Product b
    on a.product_id = b.product_id
    2. 
    select product_name, `year`, price from Sales a
    join Product using(product_id)
    备注:
    using 与 on 的区别,参照下面博客
    https://blog.csdn.net/smithallenyu/article/details/88426204
  • 相关阅读:
    集合操作
    聚合函数
    图存储3-十字链表
    图存储2-邻接表
    图存储1 临接矩阵
    字符串逆序,字符串翻转
    读写文件
    加密算法
    静态变量-动态变量
    【Qt】UserDefindeControl
  • 原文地址:https://www.cnblogs.com/tomorrow-hope/p/13824206.html
Copyright © 2020-2023  润新知