• 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

  • 相关阅读:
    WPF技巧:通过代码片段管理器编写自己常用的代码模板提示效率
    C# 8.0和.NET Core 3.0高级编程 分享笔记二:编程基础第二部分
    C# 8.0和.NET Core 3.0高级编程 分享笔记二:编程基础第一部分
    WPF教程十一:简单了解并使用控件模板
    C# 8.0和.NET Core 3.0高级编程 分享笔记一:C#8.0与NET Core 3.0入门
    WPF教程十:如何使用Style和Behavior在WPF中规范视觉样式
    概率论与数理统计图式(第一章 概率论的基本概念)1.2概率
    概率论与数理统计图式(第一章 概率论的基本概念)1.1随机事件与随机变量
    软件工程基础图式(第三章 需求分析)
    软件工程基础图式(第二章)
  • 原文地址:https://www.cnblogs.com/TuringShine/p/7843710.html
Copyright © 2020-2023  润新知