当前位置:网站首页>Limited query of common SQL operations
Limited query of common SQL operations
2022-07-05 01:46:00 【stitchshaw】
topic 1
https://www.nowcoder.com/practice/fbe36305c6dd4954a05cc2f2f12e4f4a?tpId=240&tags=&title=&difficulty=0&judgeStatus=0&rp=0
select uid, nick_name, register_time
from user_info
order by register_time asc
limit 3
select uid, nick_name, register_time
from (
select uid, nick_name,register_time,
ROW_NUMBER() over(order by register_time) as ranks # Column name to rename . Column name cannot be row_number, Otherwise, the report will be wrong
from user_info
) as t
where ranks <= 3;
#limit 3;
with t as(
select uid, nick_name,register_time,
ROW_NUMBER() over(order by register_time) as ranks # Column name to rename . Column name cannot be row_number, Otherwise, the report will be wrong
from user_info
)
select uid, nick_name, register_time
from t
where ranks <= 3;
# limit 3;
topic 2
https://www.nowcoder.com/practice/718d36d2667b48faa2168b6c1521816a?tpId=240&tags=&title=&difficulty=0&judgeStatus=0&rp=0
Mr. Cheng temporary table t, Indicates that the conditions are met ( Job search algorithm 、 Answer sheet is algorithm 、 Complete the answer sheet on the day of registration ) People's information .
The final classification , Find out the maximum score of each person and then sort .
with t as(
select t1.uid, level, register_time, score
from user_info t1 join examination_info t2 join exam_record t3 on t1.uid = t3.uid and t2.exam_id = t3.exam_id
where job=" Algorithm " and tag = ' Algorithm ' and date(register_time) = date(submit_time)
)
select uid, level, register_time, max(score) as max_score
from t
group by uid
order by max_score DESC
limit 6, 3
limit usage :【select * from tableName limit i,n 】;
i : Is the index value of the query result ( The default from the 0 Start );n : Number returned for query results
Or write directly :
select t1.uid, level, register_time, max(score) as max_score
# from user_info t1 join examination_info t2 join exam_record t3 on t1.uid = t3.uid and t3.exam_id = t2.exam_id
from user_info t1 join exam_record using(uid) join examination_info using(exam_id)
where
job = " Algorithm " # job like ' Algorithm '
and tag = ' Algorithm ' # tag like ' Algorithm '
and date(register_time) = date(submit_time) # use date function , That is, take the date
# and DATE_FORMAT(register_time, '%Y%m%d')=DATE_FORMAT(submit_time, '%Y%m%d')
group by uid
order by max_score desc
limit 6, 3 # Take the first place 7~9 strip
边栏推荐
- Win: enable and disable USB drives using group policy
- 無心劍英譯席慕容《無怨的青春》
- Wechat applet; Gibberish generator
- Common bit operation skills of C speech
- ICSI 311 Parser
- 142. Circular linked list II
- Pytorch fine tuning (Fortune): hollowed out design or cheating
- Li Kou Jianzhi offer -- binary tree chapter
- Learn tla+ (XII) -- functions through examples
- Redis master-slave replication cluster and recovery ideas for abnormal data loss # yyds dry goods inventory #
猜你喜欢
线上故障突突突?如何紧急诊断、排查与恢复
Blue Bridge Cup Square filling (DFS backtracking)
Yyds dry inventory swagger positioning problem ⽅ formula
Armv8-a programming guide MMU (3)
Application and Optimization Practice of redis in vivo push platform
如何做一个炫酷的墨水屏电子钟?
MySQL backup and recovery + experiment
微信小程序:独立后台带分销功能月老办事处交友盲盒
[swagger]-swagger learning
Do you know the eight signs of a team becoming agile?
随机推荐
Database postragesq role membership
How to build a technical team that will bring down the company?
Database postragesql client connection default
C basic knowledge review (Part 3 of 4)
JS implementation determines whether the point is within the polygon range
Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and mobile phones can also easily read literature
"2022" is a must know web security interview question for job hopping
Redis' hyperloglog as a powerful tool for active user statistics
Complex, complicated and numerous: illustration of seven types of code coupling
Win:将一般用户添加到 Local Admins 组中
微信小程序:微群人脉微信小程序源码下载全新社群系统优化版支持代理会员系统功能超高收益
微信小程序:独立后台带分销功能月老办事处交友盲盒
PHP Joseph Ring problem
Remote control service
[CTF] AWDP summary (WEB)
187. Repeated DNA sequence - with unordered_ Map basic content
Word processing software
Li Kou Jianzhi offer -- binary tree chapter
Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
Abacus mental arithmetic test