当日

SELECT
COUNT(fponder_no) as '订单量',
breed_name as '品类',
SUM(fssmoney) as '金额',
SUM(fbalance_weight) as'重量'
FROM hyd_pound
WHERE DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d')
GROUP BY
breed_name

本周

select t1.date,t2.total,t2.fponder_no,t2.fssmoney,t2.fbalance_weight from (
select subdate(curdate(),date_format(curdate(),'%w')-1) as date
UNION
select subdate(curdate(),date_format(curdate(),'%w')-2) as date
UNION
select subdate(curdate(),date_format(curdate(),'%w')-3) as date
UNION
select subdate(curdate(),date_format(curdate(),'%w')-4) as date
UNION
select subdate(curdate(),date_format(curdate(),'%w')-5) as date
UNION
select subdate(curdate(),date_format(curdate(),'%w')-6) as date
UNION
select subdate(curdate(),date_format(curdate(),'%w')-7) as date
)as t1
LEFT JOIN (SELECTDATE_FORMAT(create_date_str,'%Y-%m-%d') 'register',COUNT(*) as total,COUNT(fponder_no) as fponder_no,SUM(fssmoney) as fssmoney,SUM(fbalance_weight) as fbalance_weightFROM hyd_poundWHERE YEARWEEK(create_date_str,1) = YEARWEEK(NOW(),1)GROUP BY DATE_FORMAT(create_date_str,'%Y-%m-%d')
) as t2 ON t1.date = t2.register
ORDER BY t1.date

过去7天

select a.date,ifnull(b.count,0) as count
from (SELECT curdate() as dateunion allSELECT date_sub(curdate(), interval 1 day) as click_dateunion allSELECT date_sub(curdate(), interval 2 day) as click_dateunion allSELECT date_sub(curdate(), interval 3 day) as click_dateunion allSELECT date_sub(curdate(), interval 4 day) as click_dateunion allSELECT date_sub(curdate(), interval 5 day) as click_dateunion allSELECT date_sub(curdate(), interval 6 day) as click_date
) a left join (select date(create_date_str) as createdate, count(*) as countfrom hyd_poundgroup by date(create_date_str)
) b on a.date = b.createdate;

当月显示每一天

SELECT a.date as perDay,
ifnull(b.store_clear_weigh,0) as store_clear_weigh,
ifnull(b.real_amount,0) as real_amount FROM(select date from (
SELECT DATE_FORMAT(DATE_SUB(last_day(curdate()), INTERVAL xc-1 day), '%Y-%m-%d') as dateFROM (SELECT @xi:=@xi+1 as xc from(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) xc1,(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6) xc2,(SELECT @xi:=0) xc0) xcxc) x0 where x0.date >= (select date_add(curdate(),interval-day(curdate())+1 day)) ORDER BY date asc) a
LEFT JOIN(SELECTsum(store_clear_weigh) as store_clear_weigh,DATE_FORMAT(gmt_create,'%Y-%m-%d') as dates,SUM(real_amount) as real_amountfrom delivery_orderGROUP BY DATE_FORMAT(gmt_create,'%Y-%m-%d')) b
ON a.date=b.dates ORDER BY date asc

近半年

 SELECT
concat(t1.month,'月') as week,
IFNULL(count(ts.id),0) AS total,
IFNULL(SUM(ts.fssmoney),0) AS fssmoney
FROM
(SELECT  MONTH(DATE_FORMAT(CURDATE(), '%Y-%m-%h')) as monthUNION SELECT MONTH(DATE_FORMAT((CURDATE() - INTERVAL 1 MONTH), '%Y-%m-%h')) AS monthUNION SELECT MONTH(DATE_FORMAT((CURDATE() - INTERVAL 2 MONTH), '%Y-%m-%h')) AS monthUNION SELECT MONTH(DATE_FORMAT((CURDATE() - INTERVAL 3 MONTH), '%Y-%m-%h')) AS monthUNION SELECT MONTH(DATE_FORMAT((CURDATE() - INTERVAL 4 MONTH), '%Y-%m-%h')) AS monthUNION SELECT MONTH(DATE_FORMAT((CURDATE() - INTERVAL 5 MONTH), '%Y-%m-%h')) AS month
) t1
LEFT JOIN hyd_pound AS ts ON (MONTH(DATE_FORMAT(ts.create_date_str, '%Y-%m-%h'))= t1.month and YEAR(ts.create_date_str)=YEAR(NOW())
)
GROUP BY t1.month

SQL语句 统计 当日 本周 过去7天 当月 近半年相关推荐

  1. SQL语句统计每天、每月、每年的销售总额

    每年 SQL语句统计每天.每月.每年的销售总额 每月 SQL语句统计每天.每月.每年的销售总额 每日 SQL语句统计每天.每月.每年的销售总额 总结 SQL语句统计每天.每月.每年的销售总额 SQL语 ...

  2. SQL语句统计每天、每月、每年的数据

    SQL语句统计每天.每月.每年的数据 1.每年 select year(ordertime) 年, sum(Total) 销售合计 from 订单表 group by year(ordertime) ...

  3. SQL语句统计排行前10

    SQL语句统计排行前10 引言 一.创建表 二.插入数据 三.执行查询 1.统计当天迟到的人员名单 2.统计当月迟到次数排行前十的人员名单 引言 场景:公司每天要进行打卡上班,每个人每天也可以多次打卡 ...

  4. 数据库专题——SQL语句统计每天、每月、每年的数据

    SQL语句统计每天.每月.每年的数据 1.每年 select year(ordertime) 年, sum(Total) 销售合计   from 订单表   group by year(orderti ...

  5. sql语句统计最近七天,30天的数据, 统计当天数据总和,统计当天每小时的数据,今日金额的支出

    sql语句统计最近七天的数据 SELECTdate_format( a.date, '%c.%d' ) times,b.count AS totals FROM( SELECTcurdate( ) A ...

  6. SQL语句统计每天、每月、每年的 数据

    1.每年 select year(ordertime) 年, sum(Total) 销售合计 from 订单表 group by year(ordertime) 2.每月 select year(or ...

  7. sql语句ding_收集SQL语句统计每天、每月、每年的数据

    1.每年 select year(ordertime) as year,count(*) as count from 订单表 group by year(ordertime) 2.每月 select  ...

  8. SQL语句统计错误率

    2018年的第一篇博客就以此作为开端吧 :D 最近在项目中碰到需要统计类似错误率之类的需求,原本这功能是之前做的,但是最近测的时候发现出了点问题,显示的结果不对.这就比较尴尬了... 于是就进行deb ...

  9. Sql语句查询当天本周本月记录的where条件

    [sql] view plaincopy –查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 –查询24小时内的: se ...

最新文章

  1. 论文免费开源:NB-IoT智慧路灯监控系统
  2. AI安全最全“排雷图”来了!腾讯发布业内首个AI安全攻击矩阵
  3. 语音中的 Transformer一文打尽!
  4. 【Android FFMPEG 开发】FFMPEG 获取 AVStream 音视频流 ( AVFormatContext 结构体 | 获取音视频流信息 | 获取音视频流个数 | 获取音视频流 )
  5. centos7 nat模式配置静态ip_Centos7设置静态IP后无法上网的解决方法
  6. Eclipse程序员要掌握的常用快捷键
  7. bootstrap 栅栏布局中 col-xs-*、col-sm-*、col-md-*、col-lg-* 区别及使用方法
  8. fedora中linux改成英文,Fedora的英文界面下使用中文
  9. android中断言_我可以使用断言在Android设备上?
  10. Web UI自动化测试之元素定位
  11. 简单树匹配算法STM-实践篇
  12. 网游UI解决方案的选择(作者 鸣·铭)
  13. MariaDB安装教程
  14. 一张图理清SpringMVC工作原理
  15. Android本地视频压缩方案
  16. Mob免费验证码androidStudio实现
  17. 微信小程序开屏动画组件封装以及使用示例
  18. html锚点定位不准确问题
  19. 中心信令服务器编码,信令网的信令点编码
  20. 云开发项目如何管理资产下的设备?

热门文章

  1. 如何停止McAFee的“按访问扫描程序”
  2. ios睡眠分析 卧床 睡眠_你知道iOS 时钟里藏了这么一个睡眠小管家?(iOS)
  3. ArticulationBody的锚点位置和锚点旋转
  4. Swift版知乎日报
  5. 七彩玫瑰,脱单神器!
  6. 多分类问题的交叉熵计算
  7. 7-4 深入虎穴 (7分)
  8. 微信小程序读取数据超过20,100的限制方法
  9. 改变eclipse字体:
  10. Bioinformatics Armory第16题:Base Filtration by Quality