《学习MySQL语句》——第一天

本文展示了SQL查询的基本用法,包括选择特定条件的数据,如面积或人口超过特定值的国家,以及从用户表中按年龄、性别和名称筛选记录。还介绍了LIKE用于模糊匹配,DISTINCT去除重复值,以及ORDERBY进行排序的方法。
摘要由CSDN通过智能技术生成

select name,  population, area 
from World 
where area >= 3000000 or population >= 25000000;

 

--查询表中所有数据
select *from 表名;

--查询users表中年龄在18~25岁之间的记录
--方式1 between..and..
select *from users where age between 18 and 25;
--方式2 &&
select *from users where age>=18 && age<=25;
--方式3 and
select *from users where age>=18 and age<=25;

--查询users表中年龄为18,20,25岁的记录
--方式1 or
select *from users where age=18 or age=20 or age=25;
--方式2 in
select *from users where age in(18,20,25);

--查询users表中年龄为23,性别为女,名字为小楠的记录
select *from users where age=23 and gender='女' and name='小楠'; 

--查询users表中序号不为空的记录
select *from users where id is not null;
--查询user表中序号为空的记录
select *from users where id is null;

_:单个任意字符
%:多个任意个字符
--查询users表中姓名第一个字为李的记录
select *from users where name like '李%';
--查询users表中姓名第二个字为李的记录
select *from users where name like '_李%';
--查询users表中姓名含有李字的记录
select *from users where name like '%李%';
--查询users表中姓名是两个字的记录
select *from users where name like '__';

--查询users表中所在城市不相同的记录
--select distinct 字段 from 表名;
select distinct city from users;

--查询users表中记录,并体育成绩降序,年龄降序
select *from users order by PE desc,age desc;
#先满足第一个条件,再满足之后

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值