最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

database_leetcode2175. The Change in Global Rankings

2022-02-26 12:39 作者:您是打尖兒還是住店呢  | 我要投稿

Description

Table:?TeamPoints

+-------------+---------+ | Column Name | Type ? ?| +-------------+---------+ | team_id ? ? | int ? ? | | name ? ? ? ?| varchar | | points ? ? ?| int ? ? | +-------------+---------+ team_id is the primary key for this table. Each row of this table contains the ID of a national team, the name of the country it represents, and the points it has in the global rankings. No two teams will represent the same country.

?

Table:?PointsChange

+---------------+------+ | Column Name ? | Type | +---------------+------+ | team_id ? ? ? | int ?| | points_change | int ?| +---------------+------+ team_id is the primary key for this table. Each row of this table contains the ID of a national team and the change in its points in the global rankings. points_change can be: - 0: indicates no change in points. - positive: indicates an increase in points. - negative: indicates a decrease in points. Each team_id that appears in TeamPoints will also appear in this table.

?

The?global ranking?of a national team is its rank after sorting all the teams by their points?in descending order. If two teams have the same points, we break the tie by sorting them by their name?in lexicographical order.

The points of each national team should be updated based on its corresponding?points_change?value.

Write an SQL query to calculate the change in the global rankings after updating each team's points.

Return the result table in?any order.

The query result format is in the following example.

?

Example 1:

Input: TeamPoints table:?

+---------+-------------+--------+

| team_id | name ? ? ? ?| points |?

+---------+-------------+--------+?

| 3 ? ? ? | Algeria ? ? | 1431 ? |?

| 1 ? ? ? | Senegal ? ? | 2132 ? |

| 2 ? ? ? | New Zealand | 1402 ? |?

| 4 ? ? ? | Croatia ? ? | 1817 ? |?

+---------+-------------+--------+?

PointsChange table:?

+---------+---------------+?

| team_id | points_change |?

+---------+---------------+?

| 3 ? ? ? | 399 ? ? ? ? ? |?

| 2 ? ? ? | 0 ? ? ? ? ? ? |?

| 4 ? ? ? | 13 ? ? ? ? ? ?|

| 1 ? ? ? | -22 ? ? ? ? ? |?

+---------+---------------+

Output:?

+---------+-------------+-----------+?

| team_id | name ? ? ? ?| rank_diff |

+---------+-------------+-----------+?

| 1 ? ? ? | Senegal ? ? | 0 ? ? ? ? |?

| 4 ? ? ? | Croatia ? ? | -1 ? ? ? ?|?

| 3 ? ? ? | Algeria ? ? | 1 ? ? ? ? |?

| 2 ? ? ? | New Zealand | 0 ? ? ? ? |?

+---------+-------------+-----------+

Explanation:?

The global rankings were as follows:?

+---------+-------------+--------+------+?

| team_id | name ? ? ? ?| points | rank |?

+---------+-------------+--------+------+?

| 1 ? ? ? | Senegal ? ? | 2132 ? | 1 ? ?|?

| 4 ? ? ? | Croatia ? ? | 1817 ? | 2 ? ?|?

| 3 ? ? ? | Algeria ? ? | 1431 ? | 3 ? ?|?

| 2 ? ? ? | New Zealand | 1402 ? | 4 ? ?|

+---------+-------------+--------+------+?

After updating the points of each team, the rankings became the following:?

+---------+-------------+--------+------+?

| team_id | name ? ? ? ?| points | rank |?

+---------+-------------+--------+------+?

| 1 ? ? ? | Senegal ? ? | 2110 ? | 1 ? ?|?

| 3 ? ? ? | Algeria ? ? | 1830 ? | 2 ? ?|

| 4 ? ? ? | Croatia ? ? | 1830 ? | 3 ? ?|

| 2 ? ? ? | New Zealand | 1402 ? | 4 ? ?|

+---------+-------------+--------+------+?

Since after updating the points Algeria and Croatia have the same points, they are ranked according to their lexicographic order. Senegal lost 22 points but their rank did not change. Croatia gained 13 points but their rank decreased by one. Algeria gained 399 points and their rank increased by one. New Zealand did not gain or lose points and their rank did not change.

沒啥說的,2個公共表達(dá)式,一個是之前的排名,一個是更改后的排名。進(jìn)行比對。


database_leetcode2175. The Change in Global Rankings的評論 (共 條)

分享到微博請遵守國家法律
武宁县| 通江县| 鄂托克旗| 资兴市| 大埔县| 凤冈县| 保亭| 山东| 和政县| 榆中县| 保亭| 靖安县| 松阳县| 宁城县| 唐海县| 江都市| 呼伦贝尔市| 武乡县| 墨江| 会泽县| 织金县| 潢川县| 长宁县| 武宣县| 漳浦县| 和田市| 东安县| 贵定县| 通化市| 岢岚县| 松滋市| 静乐县| 肇庆市| 关岭| 渭南市| 开封县| 聂拉木县| 民县| 荔波县| 凭祥市| 沅江市|