当前位置:网站首页>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
边栏推荐
- Four pits in reentrantlock!
- Classification of performance tests (learning summary)
- Win: use PowerShell to check the strength of wireless signal
- Database postragesq peer authentication
- PowerShell: use PowerShell behind the proxy server
- Wechat applet: independent background with distribution function, Yuelao office blind box for making friends
- ICSI 311 Parser
- Five ways to query MySQL field comments!
- Pytorch fine tuning (Fortune): hollowed out design or cheating
- Win: use shadow mode to view the Desktop Session of a remote user
猜你喜欢
PowerShell: use PowerShell behind the proxy server
Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
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
Remote control service
Five ways to query MySQL field comments!
Complex, complicated and numerous: illustration of seven types of code coupling
Armv8-a programming guide MMU (3)
Visual explanation of Newton iteration method
Win:使用 Shadow Mode 查看远程用户的桌面会话
Runc hang causes the kubernetes node notready
随机推荐
Wechat applet: wechat applet source code download new community system optimized version support agent member system function super high income
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
MATLB | multi micro grid and distributed energy trading
Outlook: always prompt for user password
小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
One plus six brushes into Kali nethunter
R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口
Wechat applet: the latest WordPress black gold wallpaper wechat applet two open repair version source code download support traffic main revenue
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
Win: use shadow mode to view the Desktop Session of a remote user
A simple SSO unified login design
[CTF] AWDP summary (WEB)
Win:使用 PowerShell 检查无线信号的强弱
Vulnstack3
Win: use PowerShell to check the strength of wireless signal
Mysql database | build master-slave instances of mysql-8.0 or above based on docker
Database postragesql client connection default
PHP Basics - detailed explanation of DES encryption and decryption in PHP
Using openpyxl module to write the binary list into excel file