SQL数据查询语句

表名products,包含列name,price

简单查询:

搜索所有行所有列:

select * from products;

搜索指定列name

select name from products;

搜索指定列并为列取一个假名 名字

select name as 名字 from products;

搜索指定列并为表取一个假名items

select  items.name from products as items;

比较查询          >     <            =          >=           <=           !=

搜索大于1000的价格

select  price from product where p;rice > 1000;

逻辑查询and or  not

#and
select * from products where price>1000 and price <4000; 
#or
select * from products where price > 1000 or price <4000;

#not
select * from product wheere not price > 1000

 

范围查询

#between.... and... 闭区间查询连续的
select * from products where price between 1000 and 4000;

#in 查询不连续的括号里的值
select * from products where price in (999, 1000,789);

非空判断:

#查询price是空值的
select * from products where price is null;
#查询price不是空值的
select * from products where price is not null;

 排序查询:

#升序
select * from products where 条件 order by 字段名 asc;
#降序
select * from products where 条件 order by 字段名 desc;

 

 

 

 

 



posted @ 2025-12-06 11:50  光璃  阅读(3)  评论(0)    收藏  举报