zoukankan      html  css  js  c++  java
  • SQL查询语句

    今天在云和学院学习了SQL查询语句

    查询语句

    select 字段名 from 表名 where 条件(条件可不写)

    示例:select 姓名,性别,工资 from dbo.职工

    如果是所有字段可用*代替

    where表示查询条件

    select 姓名,性别,工资 from dbo.职工 where 性别='男' and 工资 not between 1500 and 2500

    delete  from  t1

    delete 删除表内记录,表存在
    drop table t1

    drop table 删除表的结构和内容

    select COUNT(distinct(仓库号)) as 仓库号 from 职工

    select SUM(工资) as 工资总数 from 职工

    select max(工资) as 最高工资 from 职工

    select min(工资) as 最低工资 from 职工

    select avg(工资) as 平均工资 from 职工

    count 是计数,sum求和,max最大数,min最小数,avg求平均值

    SQL注释有两种:

    一是用--

    二是用/**/

    between and 表示在什么区间

    like 模糊查找

    select  仓库号,MAX(工资) as 不同仓库的最高工资 from 职工  where 性别!='女' group by 仓库号

    where 与 group by关键字一起使用的时候, where过滤的是分组前的数据

    having 表示分组之后的数据过滤 select 仓库号,AVG(工资) as 不同仓库的品均工资 from 职工 group by 仓库号 having AVG(工资)>1700

    group by 是分组

    select 姓名,性别,工资 from 职工 order by 性别,工资 desc

    order by 是排序

    更新语句

    update 仓库 set 面积=950 where 城市='济南'

    select distinct(城市) from dbo.仓库 --去除重复的列值

    select 仓库号,CONVERT(char(10),创建时间,111) as 创建时间 from 仓库

    时间格式:

  • 相关阅读:
    php 请求另一个服务器接口返回数据
    yii2 安装
    无限分类的
    程序员学习能力提升三要素转载
    为什么有的人工作多年还是老样子
    随笔杂谈
    Ecshop商品描述上传中文名图片无法显示解决方法
    「PSR 规范」PSR-2 编码风格规范
    leetcode 之Set Matrix Zeroes(10)
    leetcode 之Plus One(9)
  • 原文地址:https://www.cnblogs.com/songfang/p/4154078.html
Copyright © 2011-2022 走看看