网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 常用统计求和sql语句示例
内容
    sql语句例一:求某一字段在某一时间段内数量的总和
    表名 销售 字段有:编号 金额 统计这个表在某一时间段内金额的总和
    select sum(金额) from 表 where 条件
    sql语句例二:sql读出记录并统计出某一字段的总和
    select * ,sum(字段) from 表名 where 条件 group by 字段
    sql语句例三:sql语句按每天、每月、每年统计出销售总额
    表名: 订单 字段有ordertime(订单时间),money(金额)
    根据订单时间统计每天、每月、每年的销售总额
    1、每年
    select year(ordertime) 年,
    sum(money) 销售合计
    from 订单
    group by year(ordertime)
    2、每月
    select year(ordertime) 年,
    month(ordertime) 月,
    sum(money) 销售合计
    from 订单
    group by year(ordertime),
    month(ordertime)
    3、每日
    select year(ordertime) 年,
    month(ordertime) 月,
    day(ordertime) 日,
    sum(total) 销售合计
    from 订单
    group by year(ordertime),
    month(ordertime),
    day(ordertime)
    sql语句例四:统计某月销售量前10
    表名: 销售
    字段: 编号, 商品名称 价格 日期
    统计某月商品销量最大的商品前10个商品及销量。
    select distinct top 10 商品名称, sum(价格) as 产品总价, count(*) as 销量 from 销售 group by title
    加上月份:
    select distinct top 10 商品名称, sum(价格) as 产品总价, count(*) as 销量 from 销售 where (month(sdate) = '你要查的月份数字') group by 商品名称
    统计某月商品销量最大的商品前10个商品及销量并按销量排序
    select distinct top 10 商品名称, sum(价格) as 产品总价, count(*) as 销量 from 销售 where (month(日期) = '你要查的月份数字') group by 商品名称 order by 销量 desc
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/14 10:25:27