主頁 > 資料庫 > SQL練習——LeetCode解題和總結

SQL練習——LeetCode解題和總結

2020-11-17 10:17:42 資料庫

只用于個人的學習和總結,

178. Rank Scores

 一、表資訊

 二、題目資訊

對上表中的成績由高到低排序,并列出排名,當兩個人獲得相同分數時,取并列名次,且名詞中無斷檔,

Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.

For example, given the above Scores table, your query should generate the following report (order by highest score):

 三、參考SQL

(1)方法一:直接表內連接

1 select s1.Score,count(distinct s2.Score) as 'Rank'
2 from Scores s1
3 inner join Scores s2
4 on s1.Score<=s2.Score
5 group by s1.id
6 order by count(distinct s2.Score);

分組欄位和查詢欄位不一致,可以在嵌套一層select,

解題思路:

1、欲得到排名,肯定用count進行統計,一個表肯定不行;

2、連接條件:得到大于或等于某個數的集合,比如大于等于3.50的集合就是{3.50,3.65,4.00,3.85,4.00,3.65}

3、分組:得到大于或等于某個數的6個集合組

4、去重統計:因為是排名無斷檔,需要進行去重再統計,不然就變成統計集合的個數(即大于等于某個值的個數),而不是該值在集合中排名

(2)方法二:視窗函式——dense_rank()(MySQL8.0)

1 SELECT  Score,
2  DENSE_RANK() OVER(ORDER BY Score DESC) AS 'Rank'
3 FROM Scores;

視窗函式復習:https://zhuanlan.zhihu.com/p/135119865

180. Consecutive Numbers

一、表資訊

 二、題目資訊

找出連續出現三次及以上的數字,例如,上表中,應該回傳數字 1,

Write a SQL query to find all numbers that appear at least three times consecutively. For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times.

 

 

 

三、參考SQL

方法一:多次連接

select distinct a.num as ConsecutiveNums
from Logs a
inner join Logs b on a.id=b.id+1
inner join Logs c on a.id=c.id+2
where a.num=b.num and a.num=c.num;

思路總結:

1.連續三次出現,意味著ID連續、值相等,

 2.多次連接時,讓當前記錄、下條記錄、下下條記錄拼接在一起

3.篩選值相等的行記錄,有可能連續出現大于3次,去重即可得到該num,

方法二:視窗函式——行向下偏移lead()

select distinct Num as ConsecutiveNums
from
    (select Num,
    lead(num,1) over(order by id) as next_num,
    lead(num,2) over(order by id) as next_next_num
    from Logs) t
where t.Num=t.next_num
and t.Num=t.next_next_num;

視窗函式lead():https://www.begtut.com/mysql/mysql-lead-function.html

181. Employees Earning More Than Their Managers[e]

一、表資訊

如下 Employee 表中包含全部的員工以及其對應的經理,

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

 二、題目資訊

基于如上 Employee 表,查出薪水比其經理薪水高的員工姓名,

Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.

 三、參考SQL

自連接:

1 select e1.Name as Employee
2 from Employee e1
3 inner join Employee e2
4 on e1.ManagerId=e2.Id
5 where e1.Salary>e2.Salary;

182. Duplicate Emails[e]

一、表資訊

二、題目資訊

查詢重復的郵箱

Write a SQL query to find all duplicate emails in a table named Person. For example, your query should return the following for the above table:

三、參考SQL

方法一:自己寫的

select Email
from Person
group by Email
having count(*)>1;

方法二:官方答案

1 SELECT Email FROM
2  (SELECT Email, COUNT(id) AS num
3   FROM Person
4   GROUP BY Email) AS tmp
5 WHERE num > 1;

 

183. Customers Who Never Order[e]

一、表資訊

假設一個網站上包含如下兩張表:顧客表和訂單表

Suppose that a website contains two tables, the Customers table and the Orders table.

表一:Customers 

表二:Orders 

二、題目資訊

找出沒有下過訂單的顧客姓名,

Write a SQL query to find all customers who never order anything. Using the above tables as an example, return the following:

三、參考SQL

方法一:左外連接

1 select Name as Customers
2 from Customers c
3 left join Orders o
4 on c.Id=o.CustomerId 
5 where o.Id is null;

方法二:子查詢(官方方法)

select Name as Customers
from Customers
where Id not in(
    select CustomerId from Orders
);

184. Department Highest Salary[M]

一、表資訊

表一:Employee

 

 表二:Department

二、題目資訊

查詢每個部門中,薪水最高的員工姓名及其薪水,

Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, your SQL query should return the following rows (order of rows does not matter).

 

三、參考SQL

方法一:視窗函式——dense_rank()

select d.Name as Department,t.Name as Employee,t.Salary
from
    (
    select *,
    dense_rank() over(partition by DepartmentId order by Salary DESC) as ranking
    from Employee
    ) t
inner join Department d
on t.DepartmentId=d.Id
where ranking=1;

同一層select下,欄位別名不用能與條件篩選!!!執行順序問題from——.....——where——.....——select——.....

思路:

1.用dense_rank()不斷檔的方式,給各個部門分組的工資大小排名

2.取排名為1的都是最大工資

方法二:關聯子查詢

 1 select 
 2     d.Name as Department,
 3     t.Name as Employee,
 4     t.Salary
 5 from Department d
 6 inner join
 7     (select Name,DepartmentId,Salary
 8      from Employee e
 9      where (e.DepartmentId,Salary) in
10         (select DepartmentId,max(Salary)
11         from Employee
12         group by DepartmentId)
13     ) t
14 on d.Id=t.DepartmentId;

in可以進行多屬性值(column1_name, column2_name,....)進行篩選,一一對應所篩選的欄位,

思路:

1.找出部門中最大的工資

2.讓原始表中各部門的工資等于最大工資,羅列出所有最大工資,

3.內連接查詢相關資訊

185. Department Top Three Salaries[h]

經典topN問題:記錄每組最大的N條記錄,既要分組,又要排序,

一、表資訊

表一:Employee

 表二:Department

二、題目資訊

查詢各部門薪水排名前三名的員工姓名及薪水,

Write a SQL query to find employees who earn the top three salaries in each of the department. For the above tables, your SQL query should return the following rows (order of rows does not matter).

三、參考SQL

方法一:視窗函式——dense_rank()

 1 select 
 2     d.name as Department,
 3     e.name as Employee,
 4     Salary
 5 from Department d
 6 inner join 
 7 (
 8     select name,Salary,DepartmentId,
 9     dense_rank() over(partition by DepartmentId order by Salary desc) as ranking
10     from Employee
11 ) e
12 on d.Id=e.DepartmentId
13 where ranking<=3;

思路:

1.用dense_rank(),按照部門分組并降序排列,不間斷編上排名

2.篩選排名小于等于3的記錄,就是前三工資的記錄,

(ps:用視窗函式做,思路和上題差不多,區別只是后面篩選的條數)

方法二:自連接分組篩選

 1 select 
 2     d.name as Department,
 3     e.name as Employee,
 4     Salary
 5 from Department d
 6 inner join
 7 (
 8     select e1.Id,e1.DepartmentId,e1.name,e1.Salary
 9     from Employee e1
10     inner join Employee e2
11     on e1.DepartmentId=e2.DepartmentId
12     and e1.Salary<=e2.Salary
13     group by e1.Id
14     having count(distinct e2.Salary)<=3
15 ) e
16 on d.Id=e.DepartmentId;

思路:

1.關鍵是要找出各部門前三工資的記錄:

  自連接,連接條件為部門相等,工資比我大或者相等;

  按員工分組,則組記錄為比我大或者相等全部員工記錄;

  統計組記錄條數,少于等于3條,則表示我一定是工資第三的,這里有一點注意,不能用count(*),因為和我工資相等的員工除了我本身,還有可能有其他員工,如果不去重,就會導致記錄條數大于3(假設我剛好是第三),從而篩選掉,這不是想要的結果;

2.再按需求做相關查詢即可

(ps這題的自連接條件思路和178題差不多)

196. Delete Duplicate Emails[E]

一、表資訊

二、題目資訊

洗掉郵件重復的行,當有重復值時,保留Id最小的行,

Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. For example, after running your query, the above Person table should have the following rows:

三、參考SQL

方法一:子查詢

1 delete from Person
2 where Id not in(
3     select Id from
4     (
5         select min(Id) AS Id
6         from Person
7         group by Email
8     ) t
9 );

思路:

1.子查詢找出不用洗掉的郵箱Id集合(重復郵箱的最小Id加上郵箱不重復的Id):郵箱分組,取最小Id即可,

2.洗掉時,判斷Id不在此集合即可

(ps:MySQL不讓同時對統一表進行修改和查詢操作,所以需要外層嵌套一層輔助表;min(Id)要記得起別名)

方法二:自連接

1 delete p1 from Person p1
2 inner join Person p2
3 on p1.Email=p2.Email
4 and p1.Id>p2.Id;

思路:

1.郵箱相等進行連接得到的集合為:(1)郵箱相等,Id也相等,即不重復的(2)郵箱相等,p1.Id>p2.Id(3)郵箱相等,p1.Id<p2.Id

2.把郵箱相等,p1.Id>p2.Id提取出來,洗掉端即可,這樣就保留了小和不重復的,

(ps:聯級洗掉也有這種語法——delete 表名 from .....)

197. Rising Temperature[E]

一、表資訊

二、題目資訊

以下圖為例,找出比前一天溫度高的id,

Write an SQL query to find all dates' id with higher temperature compared to its previous dates (yesterday).

Return the result table in any order.

The query result format is in the following example:

            

三、參考SQL

1 select w1.id as Id from Weather w1
2 inner join Weather w2
3 on datediff(w1.recordDate,w2.recordDate)=1
4 where w1.temperature>w2.temperature;

思路:

1.自內連的笛卡爾積中,去取出間隔相差一天的記錄,用datadiff()函式,

2.再篩選出溫度比上一天高ID即可,

(ps;日期不能進行簡單的相加相減,最好使用日期函式,https://www.w3school.com.cn/sql/sql_dates.asp)

復習日期函式:https://leetcode-cn.com/problems/rising-temperature/solution/tu-jie-sqlmian-shi-ti-ru-he-bi-jiao-ri-qi-shu-ju-b/

262. Trips and Users[H]

一、表資訊

表一:Trips

該表包含全部出租車資訊的記錄,每一條記錄有一個 Id,ClientId 和 Drive_Id 都是與 Users 表聯結的外鍵,Status 包含 completed, cancelled_by_driver, 和 cancelled_by_client 三種狀態,

The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table. Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’).

 

 

 表二:Users

該表包含全部的用戶資訊,每一個用戶都有一個 Id,Role有三種狀態:client, driver 以及 partner,

The Users table holds all users. Each user has an unique Users_Id, and Role is an ENUM type of (‘client’, ‘driver’, ‘partner’).

二、題目資訊

找出2013年10月1日至2013年10月3日期間,每一天 未被禁止的 (unbanned) 用戶的訂單取消率,

Write a SQL query to find the cancellation rate of requests made by unbanned users (both client and driver must be unbanned) between Oct 1, 2013 and Oct 3, 2013. The cancellation rate is computed by dividing the number of canceled (by client or driver) requests made by unbanned users by the total number of requests made by unbanned users.

取消率的計算方式如下:(被司機或乘客取消的非禁止用戶生成的訂單數量) / (非禁止用戶生成的訂單總數)

For the above tables, your SQL query should return the following rows with the cancellation rate being rounded to two decimal places.

三、參考SQL

方法一:子查詢篩選出有效訂單記錄

SELECT
    Request_at AS 'Day',
    round( count( CASE t_Status WHEN 'completed' THEN NULL ELSE 1 END ) / count( * ), 2 ) AS 'Cancellation Rate' 
FROM
    (
SELECT
    Request_at,
    Status as t_Status
FROM
    Trips 
WHERE
    Client_Id NOT IN ( SELECT Users_Id FROM Users WHERE Banned = 'Yes' ) 
    AND Driver_Id NOT IN ( SELECT Users_Id FROM Users WHERE Banned = 'Yes' ) 
    ) t 
WHERE
    Request_at BETWEEN '2013-10-01' 
    AND '2013-10-03' 
GROUP BY
    Request_at

思路:

1.重要一點是篩選出有效訂單記錄集合:顧客和司機都是未被禁止的!

子查詢:

  Client_Id NOT IN ( SELECT Users_Id FROM Users WHERE Banned ='Yes' ) 

  AND Driver_Id NOT IN ( SELECT Users_Id FROM Users WHERE Banned = 'Yes')

2.在上一步基礎上,統計每天分組被取消的訂單,用case when陳述句:當訂單是complated完成狀態時,回傳null,這樣count就不會計數,

方法二:連接查詢篩選出有效訂單記錄集合

https://leetcode-cn.com/problems/trips-and-users/solution/san-chong-jie-fa-cong-nan-dao-yi-zong-you-gua-he-n/

計算訂單取消率還可以用avg(Status!='completed'):

https://leetcode-cn.com/problems/trips-and-users/solution/ci-ti-bu-nan-wei-fu-za-er-by-luanz/

511. Game Play Analysis I[E]

一、表資訊

Activity表記錄了游戲用戶的行為資訊,主鍵為(player_id, event_date)的組合,每一行記錄每個游戲用戶登錄情況以及玩的游戲數(玩的游戲可能是0),

(player_id, event_date) is the primary key of this table. This table shows the activity of players of some game. Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on some day using some device.

二、題目資訊

查詢每個用戶首次登陸的日期

Write an SQL query that reports the first login date for each player.

The query result format is in the following example:

三、參考SQL

1 SELECT
2     player_id,
3     MIN( event_date ) AS first_login 
4 FROM
5     Activity 
6 GROUP BY
7     play_id 
8 ORDER BY
9     play_id;

512. Game Play Analysis II[E]

一、表資訊

同上題

二、題目資訊

查詢每個用戶首次登陸的日期所使用的設備,

Write a SQL query that reports the device that is first logged in for each player.

三、參考SQL

方法一:內連接+子查詢

1 SELECT
2     a.player_id,
3     a.device_id 
4 FROM
5     Activity AS a
6     INNER JOIN ( SELECT player_id, MIN( event_date ) AS first_login FROM Activity GROUP BY player_id ORDER BY player_id ) AS b 
7     ON a.player_id = b.player_id AND a.event_date = b.first_login 
8 ORDER BY
9     a.player_id;

思路:

1.通過子查詢查出表b:每個玩家最早登錄的日期

2.再進行內連接(或者where篩選都可以),

方法二:視窗函式dense_rank()

1 SELECT
2     player_id,
3     device_id 
4 FROM
5     ( SELECT player_id, device_id, RANK ( ) OVER ( PARTITION BY player_id ORDER BY event_date ) AS rnk FROM Activity ) AS tmp 
6 WHERE
7     rnk = 1;

思路:

1.player_id分組,event_date升序,不間斷排名

2.取排名為1即為玩家最早登錄的資訊記錄

534. Game Play Analysis III[M]——分組累加和

一、表資訊

同上

二、題目資訊

按照日期,查詢每個用戶到目前為止累積玩的游戲數,

Write an SQL query that reports for each player and date, how many games played so far by the player. That is, the total number of games played by the player until that date. Check the example for clarity.

三、參考SQL

方法一:視窗函式sum()

1 SELECT
2     player_id,
3     event_date,
4     SUM( games_played ) over ( PARTITION BY player_id ORDER BY event_date ) AS games_played_so_far 
5 FROM
6     activity;

思路:

1.player_id分組,event_date升序

2.對分組后的games_played進行累計求和

方法二:內連接后分組統計

 1 SELECT
 2     a1.player_id,
 3     a1.event_date,
 4     SUM( a2.games_played ) AS games_played_so_far 
 5 FROM
 6     activity a1
 7     INNER JOIN activity a2 ON a1.event_date >= a2.event_date 
 8     AND a1.player_id = a2.player_id 
 9 GROUP BY
10     a1.player_id,
11     a1.event_date;

思路:

1.對于這種需要分組累計統計的(求和、計數也好),內連接的連接條件一般都是非等值連接,讓主表的某個欄位的值對應連接從表的同樣欄位的多個值

   這樣對主表的該欄位進行分組后,就可以對從表的某個欄位進行統計操作,

2.涉及到需要分組兩次的話,還要注意連接條件要加多一個等值判斷,避免組內的欄位的值連接到其他組的欄位值

   沒有進行組內的等值連接條件的限定,不同組的值亂連接匹配,導致最后分組統計結果不正確,

3.得到連接總表后,按要求進行統計即可,

550. Game Play Analysis IV[M]

一、表資訊

同上題

二、題目資訊

查詢首次登錄后第二天也登錄的用戶比例,

Write an SQL query that reports the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.

The query result format is in the following example:

   

三、參考SQL

 方法一:內連接(統計連續兩天登錄)

1 SELECT
2     ROUND(
3     COUNT( CASE datediff( a1.event_date, a2.event_date ) WHEN 1 THEN 1 ELSE NULL END ) / COUNT(DISTINCT a1.player_id),2) AS fraction
4 FROM
5     activity a1
6     INNER JOIN activity a2 
7     ON a1.player_id = a2.player_id 
8     AND a1.event_date >= a2.event_date;

思路:

1.內連接的條件和思路和上題一樣

2.統計連續兩天登入,只需要同一用戶,登錄日期相差一天即可,(注意:這里不是統計首次登錄第二天也登錄的記錄,而是只要連續兩天登錄的記錄,因為開始日期可能不是最小日期)

方法二:子查詢+外連接(統計統計首次登錄第二天也登錄)

SELECT
	ROUND( COUNT( DISTINCT t.player_id ) / COUNT( DISTINCT a1.player_id ), 2 ) AS fraction 
FROM
	activity a1
	LEFT JOIN ( SELECT player_id, MIN( event_date ) AS first_login FROM activity GROUP BY player_id ) t 
	ON a1.player_id = t.player_id 
	AND DATEDIFF( a1.event_date, t.first_login ) = 1;

思路:

1.先用子查詢查出每個用戶登錄的最早時間first_login

2.左外連接:id相等,和最早登錄時間相差一天,得到的表為:第二天用戶也登錄的記錄會和first_login連接,第二天不登錄用戶irst_login則為null(不是相差一天)

3.統計第二天登錄的用戶:COUNT( DISTINCT t.player_id ),null值不統計;不能用COUNT( t.player_id is not null )

(PS:原則上 t.player_id記錄是唯一的,除非一個用戶第二天登錄會產生多條記錄,而不是記錄最后一次登錄)

方法三:視窗函式_FIRST_VALUE()

1 SELECT
2     ROUND(COUNT(DISTINCT t.player_id)/COUNT(DISTINCT a1.player_id),2) AS fraction
3 FROM activity a1
4 LEFT JOIN (SELECT player_id,first_value(event_date) over(partition by player_id ORDER BY event_date) AS first_login FROM activity) t
5 ON a1.player_id=t.player_id
6 AND DATEDIFF(a1.event_date,t.first_login)=1

569. Median Employee Salary[H]

一、表資訊

下面的員工表包含全部的員工ID,公司名稱以及每個員工的薪水,

The Employee Table holds all employees. The employee table has three columns: Employee Id, Company Name, and Salary.

二、題目資訊

找出各公司薪水的中位數,不用SQL內建函式,

Write a SQL query to find the median salary of each company. Bonus points if you can solve it without using any built-in SQL functions.

三、參考SQL

方法一:根據中位數最原始的定義

 1 SELECT
 2     e1.Id,
 3     e1.company,
 4     e1.salary
 5 FROM
 6     (SELECT Id,company,salary,@rnk:=IF(@pre=company, @rnk:=@rnk+1,1) AS rnk,@pre:=company 
 7     FROM employee,(SELECT @rnk:=0, @pre:=NULL) AS init 
 8     ORDER BY company,salary,Id
 9     ) e1
10     INNER JOIN 
11     (SELECT company,COUNT(*) AS cnt FROM employee GROUP BY Company
12     ) e2
13     ON e1.company=e2.company
14 WHERE e1.rnk IN (cnt/2+0.5,cnt/2,cnt/2+1);

思路:

中位數定義:奇數個數字時,中位數是中間的數字;偶數個數字時,中位數中間兩個數的均值(這里只列出兩個數,不求值),即,數列總個數為N,則:

  • N為奇數,中位數排序編號是(N+1)/2=N/2+0.5

  • N為偶數,中位數排序編號是N/2和N/2+1

由于一個數列N總個數不是奇就是偶(互斥),所以(N/2+0.5)和(N/2、N/2+1)也是互斥,兩個元組的元素不可能同時為整數,也就是說無論數列總個數N是奇還偶,都可以直接這樣判斷:

  中位數位置序號  IN (N/2+0.5,N/2,N/2+1)

基于上述可以得到大致的思路:

  1.對薪水進行分組排序(不間斷連續),用自定義變數方法或者MySQL8.0的ROW_NUMBER()視窗函式

  2.求總個數cnt,count(*)

  3.篩選出中位數的位置序號e1.rnk IN (cnt/2+0.5,cnt/2,cnt/2+1)

其他方法:

https://www.cnblogs.com/qcyye/p/13451067.html

https://zhuanlan.zhihu.com/p/257081415

570. Managers with at Least 5 Direct Reports[M]

一、表資訊

下面員工表中包含各部門員工資訊及其對應的經理,

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.

二、題目資訊

查詢出至少管理5個員工的經理的名稱,

Given the Employee table, write a SQL query that finds out managers with at least 5 direct report. For the above table, your SQL query should return:

三、參考SQL

方法一:子查詢

1 SELECT NAME 
2 FROM
3     employee 
4 WHERE
5     Manager_id IN ( SELECT Manager_id FROM employee GROUP BY Manger_id HAVING COUNT( * ) >= 5 );

571. Find Median Given Frequency of Numbers[H]

一、表資訊

下表記錄了每個數字及其出現的頻率,

The Numbers table keeps the value of number and its frequency.

二、題目資訊

根據每個數字出現的頻率找出中位數,

Write a query to find the median of all numbers and name the result as median. In this table, the numbers are 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 3, so the median is (0 + 0)/2 = 0.

三、參考SQL

 

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/221603.html

標籤:MySQL

上一篇:SQL練習——LeetCode解題和總結

下一篇:windows:windows系統上的常用軟體工具快捷方式

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • GPU虛擬機創建時間深度優化

    **?桔妹導讀:**GPU虛擬機實體創建速度慢是公有云面臨的普遍問題,由于通常情況下創建虛擬機屬于低頻操作而未引起業界的重視,實際生產中還是存在對GPU實體創建時間有苛刻要求的業務場景。本文將介紹滴滴云在解決該問題時的思路、方法、并展示最終的優化成果。 從公有云服務商那里購買過虛擬主機的資深用戶,一 ......

    uj5u.com 2020-09-10 06:09:13 more
  • 可編程網卡芯片在滴滴云網路的應用實踐

    **?桔妹導讀:**隨著云規模不斷擴大以及業務層面對延遲、帶寬的要求越來越高,采用DPDK 加速網路報文處理的方式在橫向縱向擴展都出現了局限性。可編程芯片成為業界熱點。本文主要講述了可編程網卡芯片在滴滴云網路中的應用實踐,遇到的問題、帶來的收益以及開源社區貢獻。 #1. 資料中心面臨的問題 隨著滴滴 ......

    uj5u.com 2020-09-10 06:10:21 more
  • 滴滴資料通道服務演進之路

    **?桔妹導讀:**滴滴資料通道引擎承載著全公司的資料同步,為下游實時和離線場景提供了必不可少的源資料。隨著任務量的不斷增加,資料通道的整體架構也隨之發生改變。本文介紹了滴滴資料通道的發展歷程,遇到的問題以及今后的規劃。 #1. 背景 資料,對于任何一家互聯網公司來說都是非常重要的資產,公司的大資料 ......

    uj5u.com 2020-09-10 06:11:05 more
  • 滴滴AI Labs斬獲國際機器翻譯大賽中譯英方向世界第三

    **桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......

    uj5u.com 2020-09-10 06:11:29 more
  • MPP (Massively Parallel Processing)大規模并行處理

    1、什么是mpp? MPP (Massively Parallel Processing),即大規模并行處理,在資料庫非共享集群中,每個節點都有獨立的磁盤存盤系統和記憶體系統,業務資料根據資料庫模型和應用特點劃分到各個節點上,每臺資料節點通過專用網路或者商業通用網路互相連接,彼此協同計算,作為整體提供 ......

    uj5u.com 2020-09-10 06:11:41 more
  • 滴滴資料倉庫指標體系建設實踐

    **桔妹導讀:**指標體系是什么?如何使用OSM模型和AARRR模型搭建指標體系?如何統一流程、規范化、工具化管理指標體系?本文會對建設的方法論結合滴滴資料指標體系建設實踐進行解答分析。 #1. 什么是指標體系 ##1.1 指標體系定義 指標體系是將零散單點的具有相互聯系的指標,系統化的組織起來,通 ......

    uj5u.com 2020-09-10 06:12:52 more
  • 單表千萬行資料庫 LIKE 搜索優化手記

    我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......

    uj5u.com 2020-09-10 06:13:25 more
  • 滴滴Ceph分布式存盤系統優化之鎖優化

    **桔妹導讀:**Ceph是國際知名的開源分布式存盤系統,在工業界和學術界都有著重要的影響。Ceph的架構和演算法設計發表在國際系統領域頂級會議OSDI、SOSP、SC等上。Ceph社區得到Red Hat、SUSE、Intel等大公司的大力支持。Ceph是國際云計算領域應用最廣泛的開源分布式存盤系統, ......

    uj5u.com 2020-09-10 06:14:51 more
  • es~通過ElasticsearchTemplate進行聚合~嵌套聚合

    之前寫過《es~通過ElasticsearchTemplate進行聚合操作》的文章,這一次主要寫一個嵌套的聚合,例如先對sex集合,再對desc聚合,最后再對age求和,共三層嵌套。 Aggregations的部分特性類似于SQL語言中的group by,avg,sum等函式,Aggregation ......

    uj5u.com 2020-09-10 06:14:59 more
  • 爬蟲日志監控 -- Elastc Stack(ELK)部署

    傻瓜式部署,只需替換IP與用戶 導讀: 現ELK四大組件分別為:Elasticsearch(核心)、logstash(處理)、filebeat(采集)、kibana(可視化) 下載均在https://www.elastic.co/cn/downloads/下tar包,各組件版本最好一致,配合fdm會 ......

    uj5u.com 2020-09-10 06:15:05 more
最新发布
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:33:24 more
  • MySQL中binlog備份腳本分享

    關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......

    uj5u.com 2023-04-20 08:28:06 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:27:27 more
  • 快取與資料庫雙寫一致性幾種策略分析

    本文將對幾種快取與資料庫保證資料一致性的使用方式進行分析。為保證高并發性能,以下分析場景不考慮執行的原子性及加鎖等強一致性要求的場景,僅追求最終一致性。 ......

    uj5u.com 2023-04-20 08:26:48 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:26:35 more
  • 云時代,MySQL到ClickHouse資料同步產品對比推薦

    ClickHouse 在執行分析查詢時的速度優勢很好的彌補了MySQL的不足,但是對于很多開發者和DBA來說,如何將MySQL穩定、高效、簡單的同步到 ClickHouse 卻很困難。本文對比了 NineData、MaterializeMySQL(ClickHouse自帶)、Bifrost 三款產品... ......

    uj5u.com 2023-04-20 08:26:29 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:25:13 more
  • Redis 報”OutOfDirectMemoryError“(堆外記憶體溢位)

    Redis 報錯“OutOfDirectMemoryError(堆外記憶體溢位) ”問題如下: 一、報錯資訊: 使用 Redis 的業務介面 ,產生 OutOfDirectMemoryError(堆外記憶體溢位),如圖: 格式化后的報錯資訊: { "timestamp": "2023-04-17 22: ......

    uj5u.com 2023-04-20 08:24:54 more
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:24:03 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:23:11 more