当前位置:网站首页>数据库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
边栏推荐
- 一道golang中关于接口和实现的面试题
- Leetcode-6127: number of high-quality pairs
- Automated testing ----- selenium (I)
- Jmeter分布式压测
- Explain in detail the principle of MySQL master-slave replication "suggestions collection"
- Leetcode-114: expand binary tree into linked list
- 牛客-TOP101-BM38
- Principle analysis of bootloader
- Detailed explanation of document operation
- Leetcode-6129: number of all 0 subarrays
猜你喜欢

Remote—基本原理介绍

Detailed explanation of document operation
![[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

两数,三数之和

DDD的Go实战

Unity vs -- the default debugging in VS is to start rather than attach to unity debugging

Sum of two numbers and three numbers

leetcode-6129:全 0 子数组的数目

Leetcode-79: word search

Jmeter分布式压测
随机推荐
In June 2021, the interview suffered a Waterloo. Is it so convoluted now
Leetcode customs clearance: hash table six, this is really a little simple
Explain in detail the principle of MySQL master-slave replication "suggestions collection"
Cloud native, Intel arch and cloud native secret computing three sig online sharing! See you today | issues 32-34
476-82(322、64、2、46、62、114)
C language file reading and writing
If the order is not paid for 30 minutes, it will be automatically cancelled. How to achieve this? (Collection Edition)
Illustration leetcode - 3. longest substring without repeated characters (difficulty: medium)
How to realize reliable transmission with UDP?
Online random coin tossing positive and negative statistical tool
一道golang中关于接口和实现的面试题
Force deduction ----- calculate the money of the force deduction bank
Learn FPGA from the bottom structure (16) -- customization and testing of pll/mmcm IP
[technical dry goods] how to ensure the idempotency of the interface?
Today's sleep quality record 75 points
Niuke-top101-bm37
Leetcode-6129: number of all 0 subarrays
[fiddlertx plug-in] use Fiddler to capture the package Tencent classroom video download (unable to capture the package solution)
Product principles of non-financial decentralized application
Unity VS—— VS中默认调试为启动而不是附加到Unity调试