leetcode刷mysql遇到的一些小tips

2021-10-23 05:35:05 字數 2226 閱讀 1970

題目是刪除重複郵箱,抄的解答

#因為mysql不允許同時對乙個表delete和select聯合操作select, 所以會select乙個虛擬的表出來

delete

from person where id

notin

(select need.id from

(select

min(id)

as id from person group

by email)

as need

);

以及作者說exist似乎可以優化一些, 有待**

datedifftimestampdiff是後減前

select timestampdiff(

day,

'2019-05-20'

,'2019-05-21');

# 1

本題不熟悉的地方在於不知道select後面的東西可以函式套函式

elect x.request_at day

,round

(sum(if

(status

!='completed',1

,0))

/count(*

),2)

'cancellation rate'

from

(select t.

*from trips t, users u1, users u2

where t.client_id=u1.users_id and t.driver_id=u2.users_id

and u1.banned=

'no'

and u2.banned=

'no'

and request_at between

'2013-10-01'

and'2013-10-03'

) xgroup

by x.request_at

order

by x.request_at;

體育館連續三天**量超過100的date 不知道**有問題

# write your mysql query statement below

select a.

*from stadium as a

inner

join stadium as b

on a.id = b.id -

1inner

join stadium as c

on b.id = c.id -

1where a.people >

100and b.people >

100and c.people >

100union

select a.

*from stadium as a

inner

join stadium as b

on a.id = b.id +

1inner

join stadium as c

on b.id = c.id +

1where a.people >

100and b.people >

100and c.people >

100;

比如, id為: 1, 2, 3, 4的滿足, 我們討論id 為2的這一天, id為2 滿足是因為, 1, 2, 3; 也可以是因為2, 3, 4

每種情況都記錄一次,那是不是這兩種情況就記錄了兩次,重複了。

select

distinct a.

*from stadium a,stadium b,stadium c

where a.people>=

100and b.people>=

100and c.people>=

100and

((a.id = b.id-

1and b.id = c.id -1)

or##a(a.id = b.id-

1and a.id = c.id +1)

or##c(a.id = b.id+

1and b.id = c.id +1)

##c)

order

by a.id

MySQL之AUTO INCREMENT遇到的問題

這幾天在做的專案資料庫需要用到mysql,對於mysql之前接觸不多,只好看使用手冊學習學習,在使用auto increment設定主鍵為自動增長的應用中,遇到了一些疑惑的問題。具體如下 建立資料表的sql指令碼為 create table person personid int auto incr...

光遇鋼琴mysql 光遇怎麼彈琴 彈琴方法

光遇的琴是15鍵,所以萌新們有很多疑惑,15鍵怎麼彈啊?怎麼全是菱形和圓啊?這又是什麼意思啊?這裡給剛來的光之後裔們解一下迷。以上圖中的1234567,熟知簡譜的大大們肯定都明白,是哆啦咪發嗦,由於光遇是15鍵,所以光遇的音階其實也只有2個音階附帶乙個更高音階的哆。那肯定也有小夥伴們問,那只有兩個音...

mysql遠端訪問所遇問題

所遇問題 解決方案 修改 etc mysql my.cnf 將bind address 127.0.0.1 修改為 bind address 0.0.0.0 localhost which is more compatible and is not less secure.bind address ...