当日

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. List嵌套List数据,全部List数组一起更新问题
  2. Win8上安装天翼宽带运行提示停止运行的问题
  3. minSdkVersion = targetSdkVersion = compileSdkVersion
  4. 如何在宝塔面板启用 ASP.NET CORE 网站并自动申请 HTTPS 证书
  5. matlabrobert锐化_基于Matlab的图像锐化的研究
  6. c语言 获取系统版本,[原创]C/C++ 实现获取Windows操作系统版本信息
  7. 在缺乏贷后数据的情况下做好策略的调整把控
  8. php集合与数组的区别,php数组和链表的区别总结
  9. RPC框架实现思路浅析
  10. 一起谈.NET技术,ASP.NET MVC 通过 FileResult 向浏览器发送文件
  11. 【Live2D】关于我在初试live2d时遇到的问题和看法
  12. 最常用的计算机色彩表示方法——RGB模式与CMYK模式
  13. 2023重庆科技学院计算机考研信息汇总
  14. 基于 SpringBoot 手写 RPC 框架
  15. 企业微信中授权小程序
  16. docker磁盘清理
  17. 微信企业号手机端清理缓存
  18. 国家开放大学计算机应用基础本科性考,精选国家开放大学电大本科《1200计算机应用基础》形考任务1试题及答案...
  19. 索引原理-索引数据结构
  20. mount point / 挂载点

热门文章

  1. Android随笔小记 Permission
  2. 我要带海大冲进世界总决赛!
  3. 【黑苹果】拯救者y7000P
  4. 致未来的路 - 思考、方向和实践
  5. Spring Data(一)|什么是Spring Data 理解
  6. cassandra_自定义Cassandra数据类型
  7. 用Android Studio写一个聊天软件(聊天室)
  8. 线程池的种类有哪些?
  9. css文字间距和文字对齐
  10. JSP与Servlet的数据交互