数据库操作
https://javaguide.cn/database/mysql/a-thousand-lines-of-mysql-study-notes.html#%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C
create database sqltest
create table student(
id int not nul,
sex char(1),
primary key(id)
)
create table cl (id int not null,sex char(1) ,primary key(id)); insert into cl (id,sex) values(12,'1'); delete from cl where id =1; select id from cl where sex='1'; update cl set sex ='0' where id =3; create unique index index_name on cl(id); drop index index_name; select select * from cl where id>10; select * from cl where name like '%a%'; | name like '__e_a%';第三字符e第五字符a select * from cl where name like '_\_%';第二个字符为_的 select * from cl where id between 12 and 23; select * from cl where id in(12,23,45); select * from cl where sex is null; = <> select distinct id from cl; select * from cl order by id DESC; select avg(salary) ,job_id from cl group by job_id; select count(*) ,job_id from cl where email like '%a%' group by job_id; select count(*) ma_id from cl group by ma_id having count(*)>5; select job_id ,max(salary) m from cl where jin is not null group by job_id having max(salary)>12000 order by m;
询最新10条新闻,只列出新闻标题和添加时间
SELECT TOP 10 Title, AddDateTime FROM News ORDER BY AddDateTime DESC
select top 3 * from a;
select top 10 percent * from a;
如果加上percent就是给我显示查询出来数据的10%.
显示5到10行的记录,即查询6行记录
select * from tablename limit 4,6;
显示第6行的记录
select * from tablename limit 5,1;
查询前n行记录
select * from tablename limit n;
把表通过降序排序,查询前n行记录(可理解成表中最大的n个数)
select * from tablename order by id desc limit n;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2019-03-17 异或