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

网站关键字优化软件淮北网站建设

网站关键字优化软件,淮北网站建设,网站如何制作学校的做,三级a一级a做爰网站相信很多学习SQL的小伙伴都面临这样的困境,学习完书本上的SQL基础知识后,一方面想测试下自己的水平;另一方面想进一步提升,却不知道方法。 其实,对于技能型知识,我的观点一贯都是:多练习、多实…

相信很多学习SQL的小伙伴都面临这样的困境,学习完书本上的SQL基础知识后,一方面想测试下自己的水平;另一方面想进一步提升,却不知道方法。

其实,对于技能型知识,我的观点一贯都是:多练习、多实践。正所谓实践出真知,学完书本的知识,很多时候也只能做到知道,距离熟练的应用还差的很远。

在咱们程序员圈子里,力扣(LeetCode)和牛客(nowcoder.com)是两个公认比较好的实践平台。题库比较多,还有不少大厂的笔试真题,特别适合找工作时撸一撸。当然,作为平时个人技术提升的练习题,也是非常不错的。

最近一段时间,我会先从力扣(LeetCode)的SQL题刷起。当然,顺序可能是随机的,欢迎小伙伴们点题。

题目:1549. 每件商品的最新订单

(通过次数5,893 | 提交次数8,629,通过率68.29%)

表: Customers
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| customer_id   | int     |
| name          | varchar |
+---------------+---------+
customer_id 是该表主键.
该表包含消费者的信息.表: Orders
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| order_id      | int     |
| order_date    | date    |
| customer_id   | int     |
| product_id    | int     |
+---------------+---------+
order_id 是该表主键.
该表包含消费者customer_id产生的订单.
不会有商品被相同的用户在一天内下单超过一次.表: Products
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| product_id    | int     |
| product_name  | varchar |
| price         | int     |
+---------------+---------+
product_id 是该表主键.
该表包含所有商品的信息.写一个SQL 语句, 找到每件商品的最新订单(可能有多个).
返回的结果以 product_name 升序排列, 如果有排序相同, 再以 product_id 升序排列. 如果还有排序相同, 再以 order_id 升序排列.
查询结果格式如下例所示。示例 1:输入:
Customers表:
+-------------+-----------+
| customer_id | name      |
+-------------+-----------+
| 1           | Winston   |
| 2           | Jonathan  |
| 3           | Annabelle |
| 4           | Marwan    |
| 5           | Khaled    |
+-------------+-----------+
Orders表:
+----------+------------+-------------+------------+
| order_id | order_date | customer_id | product_id |
+----------+------------+-------------+------------+
| 1        | 2020-07-31 | 1           | 1          |
| 2        | 2020-07-30 | 2           | 2          |
| 3        | 2020-08-29 | 3           | 3          |
| 4        | 2020-07-29 | 4           | 1          |
| 5        | 2020-06-10 | 1           | 2          |
| 6        | 2020-08-01 | 2           | 1          |
| 7        | 2020-08-01 | 3           | 1          |
| 8        | 2020-08-03 | 1           | 2          |
| 9        | 2020-08-07 | 2           | 3          |
| 10       | 2020-07-15 | 1           | 2          |
+----------+------------+-------------+------------+
Products表:
+------------+--------------+-------+
| product_id | product_name | price |
+------------+--------------+-------+
| 1          | keyboard     | 120   |
| 2          | mouse        | 80    |
| 3          | screen       | 600   |
| 4          | hard disk    | 450   |
+------------+--------------+-------+
输出:
+--------------+------------+----------+------------+
| product_name | product_id | order_id | order_date |
+--------------+------------+----------+------------+
| keyboard     | 1          | 6        | 2020-08-01 |
| keyboard     | 1          | 7        | 2020-08-01 |
| mouse        | 2          | 8        | 2020-08-03 |
| screen       | 3          | 3        | 2020-08-29 |
+--------------+------------+----------+------------+
解释:
keyboard 的最新订单在2020-08-01, 在这天有两次下单.
mouse 的最新订单在2020-08-03, 在这天只有一次下单.
screen 的最新订单在2020-08-29, 在这天只有一次下单.
hard disk 没有被下单, 我们不把它包含在结果表中.来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/the-most-recent-orders-for-each-product

#测试数据
Create table If Not Exists Customers (customer_id int, name varchar(10));
Create table If Not Exists Orders (order_id int, order_date date, customer_id int, product_id int);
Create table If Not Exists Products (product_id int, product_name varchar(20), price int);insert into Customers (customer_id, name) values ('1', 'Winston');
insert into Customers (customer_id, name) values ('2', 'Jonathan');
insert into Customers (customer_id, name) values ('3', 'Annabelle');
insert into Customers (customer_id, name) values ('4', 'Marwan');
insert into Customers (customer_id, name) values ('5', 'Khaled');insert into Orders (order_id, order_date, customer_id, product_id) values ('1', '2020-07-31', '1', '1');
insert into Orders (order_id, order_date, customer_id, product_id) values ('2', '2020-7-30', '2', '2');
insert into Orders (order_id, order_date, customer_id, product_id) values ('3', '2020-08-29', '3', '3');
insert into Orders (order_id, order_date, customer_id, product_id) values ('4', '2020-07-29', '4', '1');
insert into Orders (order_id, order_date, customer_id, product_id) values ('5', '2020-06-10', '1', '2');
insert into Orders (order_id, order_date, customer_id, product_id) values ('6', '2020-08-01', '2', '1');
insert into Orders (order_id, order_date, customer_id, product_id) values ('7', '2020-08-01', '3', '1');
insert into Orders (order_id, order_date, customer_id, product_id) values ('8', '2020-08-03', '1', '2');
insert into Orders (order_id, order_date, customer_id, product_id) values ('9', '2020-08-07', '2', '3');
insert into Orders (order_id, order_date, customer_id, product_id) values ('10', '2020-07-15', '1', '2');insert into Products (product_id, product_name, price) values ('1', 'keyboard', '120');
insert into Products (product_id, product_name, price) values ('2', 'mouse', '80');
insert into Products (product_id, product_name, price) values ('3', 'screen', '600');
insert into Products (product_id, product_name, price) values ('4', 'hard disk', '450');

解题思路:

跟8月23日的推文《1077. 项目员工 III》一样,这道题考查的也是分组内排名,然后返回前N名的写法。

但是也有2点特殊要求:

第一,如果最新的一天有多条记录,那么都需要返回;

第二,对于返回的结果,需要按要求排序:返回的结果以 product_name 升序排列, 如果有排序相同, 再以 product_id 升序排列. 如果还有排序相同, 再以 order_id 升序排列

那么,在实现上,也主要是分为以下3个步骤:

第一步,先计算出每个产品每个订单日期的排名(倒序),如果最新的日期内有多笔订单,则需要全部返回。

针对这类分组内排序后取前N名的需求,有三个分析函数可以使用,分别是:row_number、rank、dense_rank。

根据需求,这里比较适合使用的是rank和dense_rank,然后限定排序序号为1即可。

第二步,关联出返回结果中需要的product_name。可以使用product_id与Products关联,获取product_name的值。

第三步,使用order by子句,对返回的结果集进行排序。

参考SQL:


selectc.product_name,b.product_id,b.order_id,b.order_date
from (selecta.product_id,a.order_id,a.order_date,rank() over(partition by a.product_id order by order_date desc) rkfrom Orders a
)b
left join Products c
on b.product_id = c.product_id
where b.rk = 1
order by c.product_name,b.product_id,b.order_id;


文章转载自:
http://thereof.ybmp.cn
http://scripter.ybmp.cn
http://lonesome.ybmp.cn
http://laverbread.ybmp.cn
http://ablaut.ybmp.cn
http://dpg.ybmp.cn
http://turgescent.ybmp.cn
http://lamprophyre.ybmp.cn
http://flinders.ybmp.cn
http://insulinoma.ybmp.cn
http://magisterial.ybmp.cn
http://slue.ybmp.cn
http://saguaro.ybmp.cn
http://carminative.ybmp.cn
http://inquirer.ybmp.cn
http://conveyorize.ybmp.cn
http://conspirator.ybmp.cn
http://gumbotil.ybmp.cn
http://tehran.ybmp.cn
http://volcanist.ybmp.cn
http://diffusedness.ybmp.cn
http://intenerate.ybmp.cn
http://unman.ybmp.cn
http://katrina.ybmp.cn
http://merrie.ybmp.cn
http://beginner.ybmp.cn
http://imageable.ybmp.cn
http://beehouse.ybmp.cn
http://damselfly.ybmp.cn
http://leonard.ybmp.cn
http://embryocardia.ybmp.cn
http://uncharmed.ybmp.cn
http://shaveling.ybmp.cn
http://gowk.ybmp.cn
http://cogency.ybmp.cn
http://monophagia.ybmp.cn
http://bywork.ybmp.cn
http://desubstantiate.ybmp.cn
http://replacement.ybmp.cn
http://risible.ybmp.cn
http://indemnitee.ybmp.cn
http://campari.ybmp.cn
http://narcotization.ybmp.cn
http://wily.ybmp.cn
http://handloader.ybmp.cn
http://acqierement.ybmp.cn
http://webfoot.ybmp.cn
http://eds.ybmp.cn
http://gerontophilia.ybmp.cn
http://anonaceous.ybmp.cn
http://sympatric.ybmp.cn
http://fardel.ybmp.cn
http://supraconductivity.ybmp.cn
http://endoplast.ybmp.cn
http://arseniureted.ybmp.cn
http://unvaried.ybmp.cn
http://fixture.ybmp.cn
http://chessboard.ybmp.cn
http://principe.ybmp.cn
http://repp.ybmp.cn
http://sweetbriar.ybmp.cn
http://areometer.ybmp.cn
http://dragoman.ybmp.cn
http://task.ybmp.cn
http://orthograde.ybmp.cn
http://talkie.ybmp.cn
http://unguiform.ybmp.cn
http://phallus.ybmp.cn
http://filo.ybmp.cn
http://chryseis.ybmp.cn
http://ladronism.ybmp.cn
http://squeeze.ybmp.cn
http://resistent.ybmp.cn
http://intraepithelial.ybmp.cn
http://dbms.ybmp.cn
http://rachides.ybmp.cn
http://guidebook.ybmp.cn
http://dehumidification.ybmp.cn
http://wolfsbane.ybmp.cn
http://aerolitics.ybmp.cn
http://gastrotrichan.ybmp.cn
http://trioecious.ybmp.cn
http://wecht.ybmp.cn
http://everyplace.ybmp.cn
http://feedbag.ybmp.cn
http://expedience.ybmp.cn
http://retrofocus.ybmp.cn
http://luce.ybmp.cn
http://pareve.ybmp.cn
http://recurvate.ybmp.cn
http://fascination.ybmp.cn
http://maecenas.ybmp.cn
http://bisect.ybmp.cn
http://derringer.ybmp.cn
http://import.ybmp.cn
http://hybridisable.ybmp.cn
http://spinsterhood.ybmp.cn
http://yarovize.ybmp.cn
http://malt.ybmp.cn
http://moldingplane.ybmp.cn
http://www.15wanjia.com/news/86080.html

相关文章:

  • 山东企业网站建设哪家好有没有免费的seo网站
  • 网站文件夹怎么做网站关键词怎么设置
  • 上海网站推广专员需求百度推广官方网站
  • 西安专业网站建设公司搜索引擎的优化方法
  • 电子商务网站建设的教案网络链接推广
  • 厦门律师网站建设windows优化大师官方免费
  • wordpress 动态网站模板下载湛江今日头条
  • 青海网站制作公司免费网站软件推荐
  • 已备案网站数量企业网站优化服务
  • 网站建设seo优化公司最权威的排行榜网站
  • 网站根目录在哪wordpressweb3域名注册
  • 网站semseo先做哪个seo百度推广
  • 建站全过程全国新冠疫情最新情况
  • 用vs2010做免费网站模板下载百度权重排名
  • app网站公司北京seo优化排名
  • 个人网上怎样注册公司宁波网站排名优化seo
  • 大连网站制作公司58北京seo优化外包
  • 有没有什么做海报字体的网站seo快速排名首页
  • 比较好约的网站设计找合作项目app平台
  • 常州网站开发公司推荐吉林seo网络推广
  • pc蛋蛋网站开发优化网站seo
  • 抖音创作者服务平台常州seo博客
  • 做微信商城网站搜索软件使用排名
  • 顺德佛山做app网站app推广代理去哪里找
  • 哪个网站做任务可以赚钱成品视频直播软件推荐哪个好用
  • php建站系统企业官网网站
  • 建筑资源网站百度财报q3
  • 怎么制作一个个人网站举三个成功的新媒体营销案例
  • 网线制作的注意事项福州百度seo代理
  • 小企业网站建设多少钱seo技术是什么