zoukankan      html  css  js  c++  java
  • 自学--数据库笔记--第二篇--基本查询

    自学--数据库笔记--第二篇--基本查询

    worker为已制作好的员工职工表
    salary为已制作好的员工工作表

    1.

    1 --1.查询worker表中的所有字段
    2 select * 
    3 from worker

    2.

    1 --2.查询worker表中的职工姓名和性别
    2 select wname,wsex
    3 from worker

    3.

    1 --3.对查询出来的字段进行重命名
    2 select wid as '排序',wname as '姓名'
    3 from worker

    4.

    1 --1.含比较运算符的查询(查询工资在大于等于3000的职工)
    2 select wid,actualsalary
    3 from salary
    4 where actualsalary>=3000 --条件查询

    5.

    1 --2.含确定集合谓词的查询(查询工资在大于等于2000并且大于等于3000的职工)
    2 select wid,actualsalary
    3 from salary
    4 where actualsalary between 2000 and 3000 --between and 代表xx之间

    6.

    1 --3.含确定范围维持的查询(显示工号为1或2的职工的排序,姓名,性别)
    2 select wid,wname,wsex,depid
    3 from worker
    4 where depid in ('1','2') --in后面为只要有1个匹配

    7.

    1 --4.含字符匹配谓词的查询(显示名字第二个没有华字的职工姓名,性别)
    2 select wname,wsex
    3 from worker
    4 where wname not like '_华%'
    5 
    6 --4.含字符匹配谓词的查询(显示名字第二个有华字的职工姓名,性别)
    7 select wname,wsex
    8 from worker
    9 where wname like '_华%'

    8.

    1 --5.含空值谓词的查询(查询dmaster为空值的输出)
    2 select *
    3 from depart
    4 where dmaster is null

    9.

    1 --6.含多重条件运算符的查询(显示性别为男并且为党员的职工)
    2 select wname,wsex,wparty
    3 from worker
    4 where wsex='' and wparty=''
    5 
    6 --6.含多重条件运算符的查询(显示性别为男或者为党员的职工)
    7 select wname,wsex,wparty
    8 from worker
    9 where wsex='' or wparty=''

    10.

    1 --1.查询salary表中日期为2011-1-4号的总工资的平均值
    2 select AVG(totalsalary) as '2011-01-04的平均工资'
    3 from salary
    4 where sdate='2011-01-04';

    11.

    1 --2查询职工的总数
    2 select COUNT(wid) as 职工的总数
    3 from worker
    4 
    5 --2查询职工的总数
    6 select COUNT(*) as 职工的总数
    7 from worker

    12.

    1 --3.查询salary中发过工资的职工人数,一个职工只查询一次
    2 select COUNT(distinct wid) as 职工的总数 --distinct为后面的参数重复的值只计数一次
    3 from salary

    13.

    1 --4.查询salary中工资最低的职工
    2 select MIN(actualsalary) as 最低工资
    3 from salary

    14.

    1 --5.查询salary中工资最高的职工
    2 select Max(actualsalary) as 最高工资
    3 from salary

    15.

    1 --6.查询salary工资表中,2011-1-4号工资的总额
    2 select SUM(actualsalary) as 工资总额
    3 from salary
    4 where sdate='2011-01-04';

    16.

    1 --1.查询worker表中前两项职工的信息
    2 select top 2 *
    3 from worker

    17.

    1 --2.查询worker表中女职工所出现的部门号,相同的只出现一次
    2 select distinct depid as 部门号
    3 from worker
    4 where wsex=''
  • 相关阅读:
    switch case 变量初始化问题
    GDB 调试 ---转 比较全的东东
    mount不是很熟悉 转载文章了解下 转自http://forum.ubuntu.org.cn/viewtopic.php?f=120&t=257333
    转 strace
    Mysql 漏洞利用(越权读取文件,实战怎么从低权限拿到root密码)[转]
    echo,die(),print(),print_r(),var_dump()的区别
    iis7.5加fck解析漏洞后台拿shell
    Php发送post请求方法
    分享PHP小马一枚,完美绕过安全狗检测。
    性能测试-Gatling(一)
  • 原文地址:https://www.cnblogs.com/pongniwei/p/6527751.html
Copyright © 2011-2022 走看看