MySQL查询数据之单表查询

单表查询的语法:
    select 字段 from 表名(查询表中的所有数据)where 条件(加where查询表的部分数据)
    eg: select  stu_name,gender,stu_on from student;(不同字段用逗号隔开)
    * 可以替换所有的字段细信息
    eg: select * from 表名
字段重命名:
    1,字段 as ‘字段新名称’
    select  stu_name  as ‘学号’,gender  as‘性别’,stu_on from student
    查询时会直接替换成要重命名的字段,
    2,字段  (空格)‘字段新名称’
对查询结果进行排序:
    在末尾加上 order by
    默认升序: select * from student  order by score(asc)
    降序: select * from student  order by score desc
条件语句:

1.模糊查询:例如希望查询以‘小’开头的语句
    select * from student  where stu_name like ‘小__’
    (注意:一个下划线_ 代表一个字符
               两个下划线__ 代表两个字符
               百分号% 代表任何字符皆可)
2.in:
    select * from student where stu_no='20178465510' or '20178465511' or '20178465512'
    select * from student where stu_no in ('20178465510','20178465511','20178465512')
3.between,and:
    查询600-500间的数据
    select * from student where score >=500 and <=600
    select * from student where score between 500 and 600
4.is null 与 is not null查询memo字段不为空的:
    select * from student where  memo is not null
5.去重distinct:
    select distinct  stu_no,gender from student
6.使用SQL查询SQL做数学运算:
    select 5+2 result (from dual)
    dual 为一个虚拟的表,伪表 
如何将表导出为SQL语句:
    右键 ->转储SQL文件-> 选择保存位置
如何将表导出的SQL文件运行:
    在所想要导入的链接图标处右键 ->选择运行SQL文件     
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值