当前位置:网站首页>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
边栏推荐
- "2022" is a must know web security interview question for job hopping
- Interpretation of mask RCNN paper
- MySQL REGEXP:正则表达式查询
- Can financial products be redeemed in advance?
- 官宣!第三届云原生编程挑战赛正式启动!
- Wechat applet: new independent backstage Yuelao office one yuan dating blind box
- Armv8-a programming guide MMU (3)
- 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
- Win:使用 Shadow Mode 查看远程用户的桌面会话
- Abacus mental arithmetic test
猜你喜欢
Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
如何搭建一支搞垮公司的技术团队?
微信小程序:微群人脉微信小程序源码下载全新社群系统优化版支持代理会员系统功能超高收益
[flutter topic] 64 illustration basic textfield text input box (I) # yyds dry goods inventory #
[swagger]-swagger learning
MySQL regexp: Regular Expression Query
One plus six brushes into Kali nethunter
A simple SSO unified login design
Visual explanation of Newton iteration method
Blue Bridge Cup Square filling (DFS backtracking)
随机推荐
Abacus mental arithmetic test
JVM's responsibility - load and run bytecode
Remote control service
Yyds dry goods inventory [Gan Di's one week summary: the most complete and detailed in the whole network]; detailed explanation of MySQL index data structure and index optimization; remember collectio
Binary tree traversal - middle order traversal (golang)
What sparks can applet container technology collide with IOT
Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!
Heartless sword English translation of Xi Murong's youth without complaint
One click generation and conversion of markdown directory to word format
Restful Fast Request 2022.2.1发布,支持cURL导入
微信小程序:微群人脉微信小程序源码下载全新社群系统优化版支持代理会员系统功能超高收益
Es uses collapsebuilder to de duplicate and return only a certain field
微信小程序;胡言乱语生成器
PowerShell:在代理服务器后面使用 PowerShell
無心劍英譯席慕容《無怨的青春》
Li Kou Jianzhi offer -- binary tree chapter
172. Zero after factorial
小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
[flutter topic] 64 illustration basic textfield text input box (I) # yyds dry goods inventory #
流批一體在京東的探索與實踐