DQL 查询表(select的各种命令)


/*查询studenttable表*/
select *from studenttable;
/* select 字段列表   from 表名列表  where条件列表   group by分组字段  having分组之后的条件  order by排序  limit分页限定*/
/*查询多个字段**/
select name,age from studenttable;
/*查询所有字段*/
select * from studenttable;

/*去除重复的结果集*/
select distinct name,age studenttable;

/*计算age和score分数之和*/
select name,age,score,age+score from studenttable;
/*如果有null参与运算,计算结果都为null   ifnull(score,0)如果score为null,score=0*/
select name,age,score,age+ifnull(score,0) from studenttable;
/*起别名*/
select name 姓名,age 年龄,score 分数,age+ifnull(score,0) as 总分 from studenttable;*
select name 姓名,age 年龄,score 分数,age+ifnull(score,0) 总分 from studenttable;**

/*查询年龄大于20岁的*/
select *from studenttable where age>20;
/*查询年龄等于20岁的*/
select *from studenttable where age=20;
/*查询年龄不等于于20岁的 */  
select *from studenttable where age!=20;*
select *from studenttable where age<>20;
/*查询年龄大于等于20,小于等于30*/
select * from studenttable where age>=20 && age<=30;
select * from studenttable where age>=20 and age<=30;*
select * from studenttable where age between 20 and 30;**

/*注意: null值不能使用 = (!=) 判断*/
/*查询年龄17,20岁的信息   in(集合)*/
select * from studenttable where age=17 or age=20;
select * from studenttable where age in (17,20);
/*注意: null值不能使用 = (!=) 判断*/
select * from studenttable where age=nulll;/*这条是不对的*/
select * from studenttable where age is nulll;
select * from studenttable where age is not nulll;

/*like:模糊查询   _:单个任意字符     %:多个任意字符*/
/*查询姓 '赵' 的有哪些人*/
select * from studenttable where name like '赵%';
/*查询姓名第二个字是 '敏' 的人*/
select * from studenttable where name like '_敏%';
/*查询姓名是三个字的人*/
select * from studenttable where name like '___';/*3个 _*/
/*查询姓名中包含 '敏' 的人*/
select * from studenttable where name like '%敏%';\

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值