当前位置:网站首页>数据库sql语句练习题「建议收藏」
数据库sql语句练习题「建议收藏」
2022-07-25 20:52:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
1、统计同一个房屋下的车辆个数:
SELECT houseid,COUNT(*) FROM t_car GROUP BY houseId;
2、在1的基础上,统计拥有最多车辆个数的房间号
SELECT houseId,COUNT(*) as car_num FROM t_car GROUP BY houseId ORDER BY car_num DESC LIMIT 1;
3、用一条sql语句批量新增3条t_car记录
INSERT INTO `t_car` VALUES (‘00111’, ‘鄂AB1000’, ‘11111111111111111111111111111121’, ‘car_brand_01’, ‘car_color_01’, ‘car_type_01’, ‘2017-07-23 12:12:00’, ”), (‘00112’, ‘鄂AC1234’, ‘11111111111111111111111111111122’, ‘car_brand_02’, ‘car_color_02’, ‘car_type_02’, ‘2018-07-12 12:12:00’, NULL), (‘00113’, ‘鄂AD9999’, ‘11111111111111111111111111111123’, ‘car_brand_03’, ‘car_color_00’, ‘car_type_00’, ‘2018-07-12 12:12:00’, NULL);
4、删除缴费时间在2017年1月1日之前的缴费记录
DELETE FROM t_car_pay WHERE DATE(payTime)<‘2018-01-01’;
5、删除缴费时间在2017年1月1日之前的车辆记录
DELETE FROM t_car where carId in(SELECT carId from t_car_pay where DATE(payTime)<‘2018-01-01’);
DELETE c.*,p.* FROM t_car c , t_car_pay p WHERE (c.carid=p.carid ) AND DATE(p.payTime)<‘2018-01-01’; 同时删除多个表
6、根据车牌号用一条sql语句批量修改车辆的图片信息
UPDATE t_car_image set path= ‘A-00benz.jpg’ WHERE carid in (select carid from t_car where carNumber=’鄂AL0000′ )
7、查询所有车辆最新的缴费记录
select * from t_car_pay p where 1>(select COUNT(*) from t_car_pay where carId=p.carid and payTime>p.payTime) ORDER BY p.carId,p.payTime desc;
参考:
分组取前N记录
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127838.html原文链接:https://javaforall.cn
边栏推荐
- leetcode-6125:相等行列对
- Remote—实战
- Pycharm跑程序时自动进入测试模式
- How to use buffer queue to realize high concurrent order business (glory Collection Edition)
- 7.23
- Too many passwords, don't know how to record? Why don't you write a password box applet yourself
- IEC61131 address representation
- Remote—基本原理介绍
- leetcode-6126:设计食物评分系统
- Sum of two numbers and three numbers
猜你喜欢
![Vulnhub | dc: 5 | [actual combat]](/img/c6/34117bbfb83ebdf9e619f4e4590661.png)
Vulnhub | dc: 5 | [actual combat]

LeetCode通关:哈希表六连,这个还真有点简单

Chinese son-in-law OTA Ono became the first Asian president of the University of Michigan, with an annual salary of more than 6.5 million!

Basic knowledge of Marine Geology
![[paper reading] unpaired image to image translation using cycle consistent advantageous networks](/img/73/69651dd8ecfdddd1cae13a1d223d51.png)
[paper reading] unpaired image to image translation using cycle consistent advantageous networks
What's special about Huawei's innovative solutions to consolidate the foundation of ERP for small and medium-sized enterprises?

leetcode-79:单词搜索

Cesium polygon gradient texture (canvas)

leetcode-919:完全二叉树插入器

leetcode-6125:相等行列对
随机推荐
Recommend a website that converts curl commands into PHP code & a website that initiates and executes curl requests online
Illustration leetcode - 3. longest substring without repeated characters (difficulty: medium)
Add startup software items when the win system starts up
103. (cesium chapter) cesium honeycomb diagram (square)
Canvas 填充渐变
Question and answer 47: geeks have an appointment - the current monitoring system construction of CSC
Hello, I'd like to ask questions about C and database operation.
[advanced drawing of single cell] 07. Display of KEGG enrichment results
Leetcode-6125: equal row and column pairs
Leetcode-6131: the shortest dice sequence impossible to get
Pycharm跑程序时自动进入测试模式
Remote—基本原理介绍
Kubernetes advanced part learning notes
Explain the principle of MySQL master-slave replication in detail
Automated testing ----- selenium (I)
Focus on data | Haitai Fangyuan directly hits the construction idea of data security governance in the securities industry
Vulnhub | dc: 5 | [actual combat]
Leetcode-6129: number of all 0 subarrays
seven point two three
kali修改更新源(无法安全的用该源更新)