当前位置: 首页 > news >正文

力扣高频SQL 50题(基础版)第七题

文章目录

  • 力扣高频SQL 50题(基础版)第七题
    • 1068. 产品销售分析 I
      • 题目说明
      • 思路分析
      • 实现过程
        • 准备数据:
        • 实现方式:
        • 结果截图:
        • 总结:

力扣高频SQL 50题(基础版)第七题

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 的外键(reference 列)。

该表的每一行显示 product_id 在某一年的销售情况。

注意: price 表示每单位价格。

产品表 Product

±-------------±--------+

| Column Name | Type |

±-------------±--------+

| product_id | int |

| product_name | varchar |

±-------------±--------+

product_id 是表的主键(具有唯一值的列)。

该表的每一行表示每种产品的产品名称。

编写解决方案,以获取 Sales 表中所有 sale_id 对应的 product_name以及该产品的所有 yearprice

返回结果表 无顺序要求

思路分析

在这里插入图片描述

实现过程

准备数据:
Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)
Create table If Not Exists Product (product_id int, product_name varchar(10))
Truncate table Sales
insert into Sales (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000')
insert into Sales (sale_id, product_id, year, quantity, price) values ('2', '100', '2009', '12', '5000')
insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')
Truncate table Product
insert into Product (product_id, product_name) values ('100', 'Nokia')
insert into Product (product_id, product_name) values ('200', 'Apple')
insert into Product (product_id, product_name) values ('300', 'Samsung')
实现方式:
select p.product_name,s.year,s.price from Sales s,Product p where s.product_id=p.product_id;
结果截图:

在这里插入图片描述

总结:
#隐式内连接语法
select 字段名 from A表名, B表名 where 条件;
http://www.lryc.cn/news/407873.html

相关文章:

  • 【音视频】一篇文章区分直播与点播、推流与拉流
  • 3d动画软件blender如何汉化?(最新版本4.2)
  • C++学习笔记04-补充知识点(问题-解答自查版)
  • Vue el-table的自定义排序返回值为null,设置刷新页面保持排序标志,导航时elementui组件不更新
  • 一起笨笨的学C ——16链表基础
  • 信息学奥赛一本通1917:【01NOIP普及组】装箱问题
  • android user 版本如何手动触发dump
  • RedHat Linux 7.5 安装 mssql-server
  • Vue的SSR和预渲染:提升首屏加载速度与SEO效果
  • 若依ruoyi+AI项目二次开发(智能售货机运营管理系统)
  • 【SpringBoot】 4 Thymeleaf
  • 动静资源的转发操作
  • Windows系统安全加固方案:快速上手系统加固指南(上)
  • git连接远程仓库
  • 算法-----递归~~搜索~~回溯(宏观认识)
  • 【云原生】Docker搭建知识库文档协作平台Confluence
  • 序列化与反序列化的本质
  • 飞牛爬虫FlyBullSpider 一款简单方便强大的爬虫,限时免费 特别适合小白!用它爬下Boss的2024年7月底Java岗位,分析一下程序员就业市场行情
  • EXCEL 排名(RANK,COUNTIFS)
  • 【踩坑系列-JS】iframe中的url参数获取
  • 测试工作中常听到的名词解释 : )
  • Linux内网离线用rsync和inotify-tools实现文件夹文件单向同步和双向同步
  • Spring Security学习笔记(二)Spring Security认证和鉴权
  • 产品经理NPDP好考吗?
  • 【C++】:红黑树的应用 --- 封装map和set
  • unity美术资源优化(资源冗余,主界面图集过多)
  • 【git】github中的Pull Request是什么
  • gitlab查询分支API显示不全,只有20个问题
  • vue3+vite 实现动态引入某个文件夹下的组件 - glob-import的使用
  • hhhhh