SQL實戰76 考試分數 五

2021-10-11 11:26:55 字數 1940 閱讀 2483

方法一:

select b.

*from

(select job,

floor((

count(*

)+1)

/2) as `start`,

floor((

count(*

)+1)

/2)+

if(count(*

)%2=

1,0,

1) as `end`

from grade group by job) a -- 中位數的位置資訊,也就是公升序之後的排名資訊

join

(select g1.*,

(select count

(distinct g2.score)

from grade g2

where g2.score>=g1.score and g1.job=g2.job) as t_rank

from grade g1 ) b -- 不同工作(job)裡面的每個人的資訊與排名

on(a.job=b.job and b.t_rank between a.start and a.end)

order by b.id

-- 要提取中位數的資訊,恰好a有中位數的資訊,那麼聯立a,b表,並且當工作(job)相同

--並且, b的排名(rank)在a表的中位數字置之間,那麼就表明這個資訊是中位數的資訊,最後聯立

方法二(優化):

select b.

*from

( select id,job,score,

row_number()

over

(partition by job order by score desc) as t_rank

from grade ) as b ,

(select job,

floor((

count

(id)+1

)/2) as mid_start,

floor((

count

(id)+2

)/2) as mid_end

from grade

group by job ) a

where b.job = a.job

and b.t_rank between a.mid_start and a.mid_end

order by b.id;

方法三(優化):

select a.id,a.job,a.score,b.t_rank

from

( select id,job,score,

row_number()

over

(partition by job order by score desc) as ranks

from grade ) a

join

( select job,

floor((

count

(score)+1

)/2) as t_rank

from grade

group by job

union

select job,

floor((

count

(score)/2

)+1) as t_rank

from grade

group by job ) b

on a.job = b.job

and a.ranks = b.t_rank

order by a.id;

考試反思 0421省選模擬76 學傻

今天的題貌似相對比較簡單?t1 只要發現是個最短路樹就完事了。t2 是乙個做爛了的 dp 上次我的確不會 雖說對於當時而言,也已經做爛了然而我還是不會 反正這次要是再不會就不合適了。t3 就是個睿智。結果還讀錯題,連暴力分都掛沒了。樣例水坑人啊。t1 miniumcut 大意 給出 n 個點兩兩之間...

Web實戰 SQL注入

第三次嘗試,and 1 1 回顯空白 過濾了and 第四次嘗試,and 1 1 回顯空白 過濾了大小寫 第五次嘗試,anandd 1 1 回顯正常 好的,完美解決了,開始進行order by 試列數,巢狀剝離繞過 過濾了and or 開始嘗試order by 1,2,3,4,5 經測試,3 回顯正常...

SQL多表連線實戰

操作符名稱 描述inner join 如果表中至少乙個匹配,則返回行 left join 即使右邊中沒有匹配,也從左表中返回所有的行 right join 即使左表中沒有匹配,也從右邊中返回所有的行 連線查詢 如需要多張資料表的資料進行查詢,則可通過連線運算子實現多個查詢 內連線 inner joi...