zoukankan      html  css  js  c++  java
  • 数据表查询操作

    1.语法:

      select 字段列表 from 表名;

    注解:

      1.字段列表根据自身需要填写。举例:select name,sex from stu;

      2.查询所有字段可以使用*代替。举例: select * from stu;

    小插曲:

      显示当前使用的数据库命令:1.select database();          2.s;

    2.select 的特殊功能:执行函数

    举例:select 20+ 25 as 执行结果;

    3.字段列表选项

      distinct :去除掉结果集中重复行  举例:select distinct  name,sex  from  stu;//检索出来的姓名接性别没有重复的

      all:默认取的是结果集中的所有行

    4.另一种查询数据的方法

      use 数据库名

      select 字段名 from  数据库名.数据表名;//也可以查询出对应的数据。

    5.where子句

      语法:select 字段列表 from 表名 where 子句

      不加where将返回数据表中所有行,where子句会对from返回的结果集进行判断,符合条件的将被返回。

      where的本质:条件判断的结果只有真或假

      where子句中的字段只能来自于数据表中的字段名

    6.where 字段名称 in();in指定字段可取值,取其中一个值即可满足条件 -------一般用户取某个字段中符合某些要求的记录

      举例:select * from stu where name in('a','李x');//查询stu表中名字是a或者李x

      等价于:select * from stu where name = 'a' or name = '李x';

      相反的:where........not  in();除了符合条件以外的记录

    7.where 字段名称 between  A  and  B

      举例:select * from stu where id between 1 and 4;

      注解:A和B通常是数值型

    8.where 字段名 is  null

    9.where 字段名称 like

      其中like是模糊查询

      通配符:按照某种指定模式进行匹配。

      %:匹配任意多个字符。

    举例:select * from stu where name like '李%';//匹配出只要第一个汉字是李的所有人名。

      select * from stu where name like '%李%';//匹配出只要姓名中包含李的人名。

      '_':匹配出一个字符

    举例:select * from stu where name like '_';

  • 相关阅读:
    【BZOJ 3144】 [Hnoi2013]切糕
    【BZOJ 1095】 [ZJOI2007]Hide 捉迷藏
    【BZOJ 4016】[FJOI2014]最短路径树问题
    【BZOJ 2152】 聪聪可可
    【BZOJ 1095】 [ZJOI2007]Hide 捉迷藏 括号序列
    【BZOJ 3196】 Tyvj 1730 二逼平衡树 分块
    【BZOJ 2038】 [2009国家集训队]小Z的袜子(hose)
    【BZOJ 3196】 Tyvj 1730 二逼平衡树
    接下来的事
    【BZOJ 1189】 [HNOI2007]紧急疏散evacuate
  • 原文地址:https://www.cnblogs.com/Worssmagee1002/p/7672530.html
Copyright © 2011-2022 走看看