数据库操作

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;

 

posted on 2022-03-17 15:16  cltt  阅读(38)  评论(0编辑  收藏  举报

导航