SQL·查询语句与SQL操作语句

MySQL 查询语句


1】SQL读取N条数据

select * from life_data limit 0,10 //第一条至第十条
select * from life_data limit 10,20 //第十条至第二十条


2】SQL根据id字段查询一整行数据

select * from life_data where id = '2022072412223412320221002'


3】SQL根据id字段 查询另一个字段的内容

select position from life_data where id = '2022072412223412320221002'


4】SQL根据id查询一条数据并且含第一条

select * from life_data GROUP BY id = '2022072412223412320221004'


5】SQL根据id查询往下10条数据

select * from life_data where id < '2022072412223412320221002' order by id desc limit 0,3 //向下读取3条


6】SQL根据id查询往上10条数据

select * from life_data where id > '2022072412223412320221002' order by id asc limit 0,2 //向上读取2条


7】SQL查询整表全部数据

select * from life_data

SQL·操作语句

8】SQL根据id更新某字段中的值 ‘WHERE’ 后面是条件

UPDATE `life_data` SET `idSchool` = '14', `userid` = '24' WHERE `life_data`.`id` = '123'

9】SQL根据id删除一整条数据

DELETE FROM `life_data` WHERE `life_data`.`id` = '12'

10】SQL插入数据

INSERT INTO `life_data` (`id`, `idSchool`, `userid`) VALUES ('1234', '1', '2')

11】MySQL根据id替换某字段里部分内容

UPDATE `life_data` SET `arrGood`=replace(arrGood,'1002','1004') WHERE `life_data`.`id` = '202207241222341232022103'

12】MySQL根据id对某字段内容值 +1

update `life_data` set ids = ids + 1  where id = 1;

13】MySQL根据字段 宿舍存在的内容 (SQL查找内容)

select * from `life_data` where `idSchool` = '1001' AND `intShow` >0 AND `texts` like '%念得%' OR `arrLabel` like '%跑腿%' order by id desc limit 30

36 Views
分享你的喜爱
默认图片
linwute

我要像梦一样自由,像大地一样宽容;
在艰辛放逐的路上,点亮生命的光芒;
我要像梦一样自由,像天空一样坚强;
在曲折蜿蜒的路上,体验生命的意义;

留下评论