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 '_';

  • 相关阅读:
    Android 接口中含有" "不能正常显示
    android
    EditText禁止自动弹出键盘
    相册选择照片
    Android完美获取状态栏高度、标题栏高度、编辑区域高度的获取
    Android WebView获取UserAgent
    php extract()用法
    php的安装和破解
    php 兼容换行符
    php 引用
  • 原文地址:https://www.cnblogs.com/Worssmagee1002/p/7672530.html
Copyright © 2011-2022 走看看