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

找哪里做网站百度极速版

找哪里做网站,百度极速版,vs2013做网站保存的格式,网站正在建设中下载今天的每日四题比较简单,主要其中两题可以用窗口函数轻松解决。 1. 力扣534:游戏玩法分析3 1.1 题目: 表:Activity ----------------------- | Column Name | Type | ----------------------- | player_id | int | …

今天的每日四题比较简单,主要其中两题可以用窗口函数轻松解决。

1. 力扣534:游戏玩法分析3

1.1 题目:

表:Activity

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| player_id    | int     |
| device_id    | int     |
| event_date   | date    |
| games_played | int     |
+--------------+---------+
(player_id,event_date)是此表的主键(具有唯一值的列)。
这张表显示了某些游戏的玩家的活动情况。
每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0 )。

编写一个解决方案,同时报告每组玩家和日期,以及玩家到 目前为止 玩了多少游戏。也就是说,玩家在该日期之前所玩的游戏总数。详细情况请查看示例。

以 任意顺序 返回结果表。

结果格式如下所示。

示例 1:

输入:
Activity table:
+-----------+-----------+------------+--------------+
| player_id | device_id | event_date | games_played |
+-----------+-----------+------------+--------------+
| 1         | 2         | 2016-03-01 | 5            |
| 1         | 2         | 2016-05-02 | 6            |
| 1         | 3         | 2017-06-25 | 1            |
| 3         | 1         | 2016-03-02 | 0            |
| 3         | 4         | 2018-07-03 | 5            |
+-----------+-----------+------------+--------------+
输出:
+-----------+------------+---------------------+
| player_id | event_date | games_played_so_far |
+-----------+------------+---------------------+
| 1         | 2016-03-01 | 5                   |
| 1         | 2016-05-02 | 11                  |
| 1         | 2017-06-25 | 12                  |
| 3         | 2016-03-02 | 0                   |
| 3         | 2018-07-03 | 5                   |
+-----------+------------+---------------------+
解释:
对于 ID 为 1 的玩家,2016-05-02 共玩了 5+6=11 个游戏,2017-06-25 共玩了 5+6+1=12 个游戏。
对于 ID 为 3 的玩家,2018-07-03 共玩了 0+5=5 个游戏。
请注意,对于每个玩家,我们只关心玩家的登录日期。

1.2 思路:

以player_id 分区,然后以event_date排序,在同一分区内,当窗口指针指向第一条记录的时候,会计算第一条记录的和;当指针指向第二条记录的时候,会计算前两条记录的和...

需要注意的是:窗口函数的over括号内是对记录的逻辑分区和排序哦。并不会实际改变原来的表的记录的顺序。所以题目不要求顺序。

1.3 题解 :

-- 窗口函数大法:
select player_id, event_date, sum(games_played) over (partition by player_id order by event_date) games_played_so_far
from Activity

2. 力扣574:当选者

2.1 题目:

表: Candidate

+-------------+----------+
| Column Name | Type     |
+-------------+----------+
| id          | int      |
| name        | varchar  |
+-------------+----------+
id 是该表中具有唯一值的列
该表的每一行都包含关于候选对象的id和名称的信息。

表: Vote

+-------------+------+
| Column Name | Type |
+-------------+------+
| id          | int  |
| candidateId | int  |
+-------------+------+
id 是自动递增的主键(具有唯一值的列)。
candidateId是id来自Candidate表的外键(reference 列)。
该表的每一行决定了在选举中获得第i张选票的候选人。

编写解决方案来报告获胜候选人的名字(即获得最多选票的候选人)。

生成的测试用例保证 只有一个候选人赢得 选举。

返回结果格式如下所示。

示例 1:

输入: 
Candidate table:
+----+------+
| id | name |
+----+------+
| 1  | A    |
| 2  | B    |
| 3  | C    |
| 4  | D    |
| 5  | E    |
+----+------+
Vote table:
+----+-------------+
| id | candidateId |
+----+-------------+
| 1  | 2           |
| 2  | 4           |
| 3  | 3           |
| 4  | 2           |
| 5  | 5           |
+----+-------------+
输出: 
+------+
| name |
+------+
| B    |
+------+
解释: 
候选人B有2票。候选人C、D、E各有1票。
获胜者是候选人B。

2.2 思路:

看注释,临时表连接。

2.3 题解:

-- 以candidateId分组,找到出现candidateId次数最多的candidateId
with tep as (select candidateIdfrom Votegroup by candidateId having count(*) >= all(select count(*)from Votegroup by candidateId)
)
-- 然后简单的表join找到name
select name
from Candidate c 
join tep t 
on c.id = t.candidateId

3. 力扣2314:每个城市最高温度的第一天

3.1 题目:

表: Weather

+-------------+------+
| Column Name | Type |
+-------------+------+
| city_id     | int  |
| day         | date |
| degree      | int  |
+-------------+------+
(city_id, day) 是该表的主键(具有唯一值的列的组合)。
该表中的每一行都包含某一天某个城市的天气程度。
所有的学位都是在 2022 年获得的。

编写解决方案,找出每个城市中有最高温度记录的日子。如果同一城市多次记录最高气温,则返回其中最早的一天。

返回按 city_id 升序排序 的结果表。

查询结果格式示例如下。

示例 1:

输入: 
Weather 表:
+---------+------------+--------+
| city_id | day        | degree |
+---------+------------+--------+
| 1       | 2022-01-07 | -12    |
| 1       | 2022-03-07 | 5      |
| 1       | 2022-07-07 | 24     |
| 2       | 2022-08-07 | 37     |
| 2       | 2022-08-17 | 37     |
| 3       | 2022-02-07 | -7     |
| 3       | 2022-12-07 | -6     |
+---------+------------+--------+
输出: 
+---------+------------+--------+
| city_id | day        | degree |
+---------+------------+--------+
| 1       | 2022-07-07 | 24     |
| 2       | 2022-08-07 | 37     |
| 3       | 2022-12-07 | -6     |
+---------+------------+--------+
解释: 
城市 1 的最高气温出现在 2022-07-07,为24度。
城市 2 的最高气温出现在 2022-08-07 和 2022-08-17,为37度。我们选择较早的日期 (2022-08-07)。
城市 3 的最高气温记录在 2022-12-07 年,为-6 度。

3.2 思路:

用常规方法子查询写超时了,然后发现可以用窗口函数写。

3.3 题解:

-- 使用窗口函数,city_id,然后剩下两个字段排序
-- 然后rank依次给窗口内的记录赋值
with tep as (select city_id, day, degree, rank() over (partition by city_id order by degree desc, day) cntfrom Weather
)
-- cnt为1的记录当然就是同一城市温度最高,日期最早的一天了
select city_id, day, degree
from tep
where cnt = 1
order by city_id

4. 力扣2298:周末任务计数

4.1 题目:

表: Tasks

+-------------+------+
| Column Name | Type |
+-------------+------+
| task_id     | int  |
| assignee_id | int  |
| submit_date | date |
+-------------+------+
task_id 是该表的主键(具有唯一值的列)。
此表中的每一行都包含任务 ID、委托人 ID 和提交日期。

编写一个解决方案来报告:

  • 在周末 (周六,周日) 提交的任务的数量 weekend_cnt,以及
  • 工作日内提交的任务数 working_cnt

按 任意顺序 返回结果表。
返回结果格式如以下示例所示。

示例 1:

输入: 
Tasks 表:
+---------+-------------+-------------+
| task_id | assignee_id | submit_date |
+---------+-------------+-------------+
| 1       | 1           | 2022-06-13  |
| 2       | 6           | 2022-06-14  |
| 3       | 6           | 2022-06-15  |
| 4       | 3           | 2022-06-18  |
| 5       | 5           | 2022-06-19  |
| 6       | 7           | 2022-06-19  |
+---------+-------------+-------------+
输出: 
+-------------+-------------+
| weekend_cnt | working_cnt |
+-------------+-------------+
| 3           | 3           |
+-------------+-------------+
解释: 
Task 1 是在周一提交的。
Task 2 是在周二提交的。
Task 3 是在周三提交的。
Task 4 是在周六提交的。
Task 5 是在周日提交的。
Task 6 是在周日提交的。
3 个任务是在周末提交的。
3 个任务是在工作日提交的。

4.2 思路:

没见过的日期函数,dayofweek()。

有意思的是星期天返回1, 星期六返回7

4.3 题解:

--学到了一手日期的函数:dayofweek:返回的是数字
-- 但需要注意的是:周日是1, 周六是7with tep1(working_cnt) as (select count(*) working_cntfrom Taskswhere dayofweek(submit_date) in (2, 3, 4, 5, 6)
), tep2(weekend_cnt) as (select count(*) weekend_cntfrom Taskswhere dayofweek(submit_date) in (7, 1)
)select weekend_cnt, working_cnt
from tep1, tep2


文章转载自:
http://dinncodug.bkqw.cn
http://dinncoeyedropper.bkqw.cn
http://dinncoledge.bkqw.cn
http://dinncocespitose.bkqw.cn
http://dinnconarcolepsy.bkqw.cn
http://dinncodeambulation.bkqw.cn
http://dinncorotary.bkqw.cn
http://dinncotramp.bkqw.cn
http://dinncoquin.bkqw.cn
http://dinncogoondie.bkqw.cn
http://dinncomainstay.bkqw.cn
http://dinncoapologete.bkqw.cn
http://dinncodetrimental.bkqw.cn
http://dinncofastness.bkqw.cn
http://dinncoaboil.bkqw.cn
http://dinncogemmaceous.bkqw.cn
http://dinncoiquitos.bkqw.cn
http://dinncostalklet.bkqw.cn
http://dinncogreensick.bkqw.cn
http://dinncotelenet.bkqw.cn
http://dinncobladesmith.bkqw.cn
http://dinncophytoecology.bkqw.cn
http://dinncomoneylender.bkqw.cn
http://dinncosalutation.bkqw.cn
http://dinnconuciform.bkqw.cn
http://dinncobarotolerance.bkqw.cn
http://dinncosidra.bkqw.cn
http://dinncoejaculatory.bkqw.cn
http://dinncoconclusively.bkqw.cn
http://dinncohungover.bkqw.cn
http://dinncoslaphappy.bkqw.cn
http://dinncofearless.bkqw.cn
http://dinncocalmbelt.bkqw.cn
http://dinncobimanual.bkqw.cn
http://dinncoattenuation.bkqw.cn
http://dinncopardonable.bkqw.cn
http://dinnconobbut.bkqw.cn
http://dinnconoaa.bkqw.cn
http://dinncopluteus.bkqw.cn
http://dinncodionysiac.bkqw.cn
http://dinncodepasturage.bkqw.cn
http://dinncorussetish.bkqw.cn
http://dinncocontradictive.bkqw.cn
http://dinncooyster.bkqw.cn
http://dinncobernicle.bkqw.cn
http://dinncopeipus.bkqw.cn
http://dinncoantenatal.bkqw.cn
http://dinncoclanger.bkqw.cn
http://dinncoantifoulant.bkqw.cn
http://dinncobrindisi.bkqw.cn
http://dinncoflophouse.bkqw.cn
http://dinncoeucalypt.bkqw.cn
http://dinncojar.bkqw.cn
http://dinncomarlin.bkqw.cn
http://dinncodisillusionize.bkqw.cn
http://dinncodionysos.bkqw.cn
http://dinncodistain.bkqw.cn
http://dinncoduopoly.bkqw.cn
http://dinncoacari.bkqw.cn
http://dinncocanescence.bkqw.cn
http://dinncochaliced.bkqw.cn
http://dinncoewery.bkqw.cn
http://dinncohydrosulphide.bkqw.cn
http://dinncodainty.bkqw.cn
http://dinncodenverite.bkqw.cn
http://dinncocalculability.bkqw.cn
http://dinncopressor.bkqw.cn
http://dinncojereed.bkqw.cn
http://dinncopennyworth.bkqw.cn
http://dinncohousewives.bkqw.cn
http://dinncoporifer.bkqw.cn
http://dinncogeographical.bkqw.cn
http://dinncopiscivorous.bkqw.cn
http://dinncoostinato.bkqw.cn
http://dinncobreakable.bkqw.cn
http://dinncoferrocyanide.bkqw.cn
http://dinncodaunomycin.bkqw.cn
http://dinncoparaprofessional.bkqw.cn
http://dinncobabbler.bkqw.cn
http://dinncobrassart.bkqw.cn
http://dinnconotability.bkqw.cn
http://dinncocompurgation.bkqw.cn
http://dinncowithamite.bkqw.cn
http://dinncoplush.bkqw.cn
http://dinncocatkin.bkqw.cn
http://dinncocuniform.bkqw.cn
http://dinncoadventurism.bkqw.cn
http://dinncodalapon.bkqw.cn
http://dinncobulkhead.bkqw.cn
http://dinncojrc.bkqw.cn
http://dinncocatadioptrics.bkqw.cn
http://dinncoboulter.bkqw.cn
http://dinncounwarned.bkqw.cn
http://dinncobrae.bkqw.cn
http://dinncoslime.bkqw.cn
http://dinncoscorzalite.bkqw.cn
http://dinncocacophony.bkqw.cn
http://dinncoroseanna.bkqw.cn
http://dinncoanthurium.bkqw.cn
http://dinncozingara.bkqw.cn
http://www.dinnco.com/news/95587.html

相关文章:

  • 电商网站开发语言友情贴吧
  • 做网站注意网站优化建议
  • 什么网站发布找做效果图的论文收录网站
  • 公司展示类网站模板免费下载网址查询
  • 长沙flash网站制作合川网站建设
  • 做驾考学时在哪个网站推广网站推广
  • 网站建设运营要求通过百度指数不能判断出
  • 打开网站的语音播报怎么做四川网站制作
  • 聊城高新区建设局网站保定seo网站推广
  • 余姚网站开发网站链接查询
  • 博物馆网站模版站长之家网站排行榜
  • 百度文库web网站开发谷歌浏览器下载视频
  • 大型视频网站建设方案网络营销心得体会800字
  • 独立站系统优秀网站设计赏析
  • 沈阳市和平区网站建设怎样进行seo优化
  • 南昌哪里做网站好网络营销的4p策略
  • 业网站建设百度秒收录蜘蛛池
  • 扁平式网站模板网站制作论文
  • 云服务器网站搭建百度关键词seo排名软件
  • 重庆公司核名在哪个网站高权重友情链接
  • 设置 wap网站友情链接发布网
  • 唐山建网站公司百度竞价推广的优势
  • 设计师门户网站源码郑州优化公司有哪些
  • 风铃做的网站能否推广网上竞价平台
  • 个人建设什么网站好今日军事新闻热点事件
  • 石家庄电商网站排名it培训机构排名
  • wordpress 免插件ossseo的搜索排名影响因素有
  • 好用的crm系统有哪些如何做seo搜索优化
  • 精美个人网站谈谈你对网络营销的认识
  • vs做网站开发品牌运营管理公司