zoukankan      html  css  js  c++  java
  • SQL课堂笔记查询表1

          2017/11.10

    SQL的主要功能:

     1.数据定义
     2.数据查询
     3.数据操作
     4.数据控制功能(了解)
     
     
    SQL语言的动词:

     数据定义:create,drop, alter
     数据查询:select
     数据操作:insert,update,deledte
     数据控制:crant,revoke
     

     数据查询语句的基本格式:
      select[distinct] 目标列      //distinct去掉记录中的重复值
      from 基本表(或视图)
      [where 条件表达式]
      [group by 列名1 [having内部函数表达式] ]
      [order by 列名2 [asc(升序)/desc(降序)] ] 
           中括号中的表示可选项,可有可无

     select语句的含义是,根据where子句条件表达式,从from子句中的基本表达式或视图中检索出满足条件的元祖,
     按select子句的目标列,选出元组中的相应列形成新的表.新表记录中可以按order by 子句中指定的列名2进行
     升序或降序排序,还可以按group不用子句指定的列名1的值对元组进行分组

     1.select语句:
      ues 数据库名
      go
      select * from 表名     --查询所有内容
      select sno,sname from 表名   --查询指定内容
      select sno,sname,2007-sage as出生年月  from student  --as出生年月,表示重命名新列名
                 --不写as也行,用空格表示
      
      select top 3 * from student  --查询前3条语句
      select top 6 name from student  --查询前6条的单个信息(姓名等)
      
      查询结果放入新表中:
      select sname,ssex into newstudent from student    --newtable会自动创建

      where子句:
       1.查询所有性别为男生的学生:

        select * from student where ssex='男'

       2.检索年龄在19岁以上的学号,姓名和性别:

        select sno,sname,ssex from student where ssage>19

       3.查询年龄在18-20岁之间的学号和姓名:
     
        select sno,sname from student where age  not between 18 and 20
        select sno,sanem from student where age<18 or age>20
      in查询:
       查询专业为计算机,通信的所有学生的学生:
       select * from student where sdept in ('计算','通信')

      or查询:
       
      and查询:
       select * from student where sdept='计算机' and ssex='男'

      字符匹配查询:

       通配符:
        _ (下划线)表示任何一个字符
       
        % 表示任何多个字符(包括0个)

       查询课程名第二个字符为据的课程:

        select * from course where cname like '_据%'

       access的通配符为:
         ?代表单一字符     相当于 _
         *代表0或多个字符     相当于%
         #代表单一数字(0-9)

        select * from course where cname like '?据*'

      空值查询:
       查询没有填写年龄的学生姓名
        select  sname from student where sage is null

  • 相关阅读:
    安装 pgadmin4 docker
    DevExpress 、XtraGrid 自定义统计数据
    LINQ之Join(from join on )与GroupJoin(from join on into)将两个集合进行关联与分组
    LINQ之LookUp
    LINQ之GroupBy(group p by into)
    LINQ之SelectMany(from.. from..复合from子句)
    Row_number over (Partition by yyy) in Entity Framework
    为表或者表字段添加扩展属性(MS_Description、sp_addextendedproperty、注释)
    学习vue,待续中。。。
    用Python爬取《王者荣耀》英雄皮肤数据并可视化分析,用图说话
  • 原文地址:https://www.cnblogs.com/TuringShine/p/7843710.html
Copyright © 2011-2022 走看看