【SQL】数据筛选过滤(初级)

对于SQL数据库,我们可以通过select和where组合来实现特定数据的搜索和过滤。

1、读取表test_table中的所有数据,可以用*来筛选:

select * from test_table;

2、读取表test_table中的所有数据,并根据price做升序排序

select * from test_table ORDER BY price ASC;

3、读取表test_table中的所有数据,并根据price做降序排序

select * from test_table ORDER BY price DESC;

4、读取表test_table中的所有price,并保证获取的数据不重复出现

select DISTINCT price from test_table;

5、读取表test_table中的所有price,并保证获取的数据不重复出现

select DISTINCT price from test_table;

6、读取表test_table中的所有price,并保证获取的数据不重复出现,只显示前面5个

select DISTINCT price from test_table LIMIT 5;

7、读取表test_table中的所有price,只显示前面5个

select price from test_table LIMIT 5;

8、读取表test_table中的所有price,只显示第6-10个数据

select price from test_table LIMIT 5 OFFSET 5;

9、读取表test_table中的所有price和name,优先根据price排序,然后根据name排序

select price,name from test_table ORDER BY price, name;

10、读取表test_table中的所有price和name,优先根据price降序排序,然后根据name升序排序

select price,name from test_table ORDER BY price DESC, name;

11、读取表test_table中的所有price和name,其中price大于10

select price,name from test_table where price > 10;

12、读取表test_table中的所有price和name,其中price小于等于10

select price,name from test_table where price <= 10;

13、读取表test_table中的所有price和name,其中price小于等于10

select price,name from test_table where price <= 10;

14、读取表test_table中的所有price和name,其中price不等于10

select price,name from test_table where price != 10;

15、读取表test_table中的所有price和name,其中price大于5小于10

select price,name from test_table where price BETWEEN 5 AND 10;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值