SQL查询(一)

一、SELECT 语句:

表:student

字段:S_id;S_name;S_birth;S_sex

表:score
字段:S_id;C_id;S_score

1、查询全体学生记录:

①、Select *  from  student;

②、select  S_id,S_name,S_birth,S_sex  from student;

2、按照某一个条件查询

#select field1,field2  from table where  field  >  <  =  >=  <=

①、select * from  student  where S_id  =  '02';

②、select * from student  where S_birth <='1992.05.02'

3、按照多个条件查询

#select  field1,field2  from  table  where   field   <  >   =   <=  >=  and  field  <  >  =  <=  >=

select  * from  student  where  S_birth  <= ' 1993.03.05'  and  s_sex ='女';

4、按照条件or查询(只要满足or左右的条件,即可查询到数据)

#select  field1,field2  from  table  where  field  <  >  =   <=   >=   or  field  <  >   =   <=  >=;

select  *  from  student  where  S_birth  <='1993.03.05' or S_sex = '女'  or  S_id = '01';

5、按照条件区间查询(between     and)

#select   field1,field2  from  table  where  field  (not)between  value  and  value;

select  *  from   student  where  S_birth   between  '1993.03.05'  and  '1995.06.12';

select *  from  student   where S_birth  not   between   '1993.03.05'   and  '1995.06.12';

6、在某个范围查询(in)

#select  field1,field2  from  table   where  field  (not) in  (value,value);

select  *  from  student  where   S_birth  in  ('1993.03.06','1996.06.12');

select  *  from   student where  S_birth  not in  ('1993.03.06','1996.06.12');

7、模糊查询

#select  field1,field2  from  table   where   field   (not) like  'value%'(%value%-只要带周,不管在哪个位置);

select  *  from  student  where   S_name  like  '周%'

select  *  from   student  where  S_name  like  '%周%'

8、统计查询(count)

#select  count(field1) from  table where 

#select  count(*)from table  where

select  count(*)from  student   where  S_name  like'周%';

9、统计查询(count)as

#select  field1  as  value  from  table   where

select  count(*) as   统计结果  from  student   where   S_name  like  '周%';

10、多表查询

#select * from filed1,filed2 where filed1.某字段=filed2.某字段  (两表必须两个表都有共同字段)

select * from student,score where student.s_id=score.s_id

11、

 

 

      

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

村东头老杨

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值