task:
sql:
# 将某个值插入到报表
- insert into report_app_detail(curr_date,key_name,key_value) values(:curr_date,:title,:curr_value)
# 删除当日报表信息
- delete from report_app_detail where curr_date='%s'
# 获取用户信息
- select '#当前日期#' curr_date,'当日新增用户数' title,count(*) curr_value from app_user.user_info where create_time>='#当前日期#' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#'curr_date,'累计用户数' title,count(*) curr_value from app_user.user_info where create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#'curr_date,'累计小组数' title,count(*) curr_value from app_user.group_info where group_status=1 and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#'curr_date,'累计小组成员数' title,count(*) curr_value from app_user.group_member where member_is_valid=1 and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day) and group_id not in (select id from app_user.group_info where group_status = '0')
# 获取解锁码信息
- select '#当前日期#' curr_date,'累计卡总数' title,count(*) curr_value from app_goods.card_info where create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计实体卡总数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计实体卡出库总数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and card_use_status='1' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'实体卡累计解锁总数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and card_use_status='1' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'实体卡当日解锁数' title,count(*) curr_value from app_goods.card_info where card_type = '1' and card_use_status='1' and (card_unlock_time>='#当前日期#' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day))
union all
select '#当前日期#' curr_date,'累计虚拟卡总数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计虚拟卡出库总数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and card_use_status='1' and create_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'累计虚拟卡解锁总数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and card_use_status='1' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day)
union all
select '#当前日期#' curr_date,'虚拟卡当日解锁数' title,count(*) curr_value from app_goods.card_info where card_type = '0' and card_use_status='1' and (card_unlock_time>='#当前日期#' and card_unlock_time<DATE_ADD('#当前日期#',INTERVAL 1 day))
# 本日订单查询
- select
date(create_time) curr_date,
count(distinct user_id) user_c,
count(1) order_c,
sum(if(order_status=0,1,0)) dzf_c,
sum(if(order_status=1,1,0)) yzf_c,
sum(if(order_status=2,1,0)) tkz_c,
sum(if(order_status=3,1,0)) ytk_c,
sum(if(order_status=9,1,0)) ygb_c,
sum(if(order_type=0,1,0)) kc_c,
sum(if(order_type=1,1,0)) jsm_c,
sum(if(pay_type=0,1,0)) wx_c,
sum(if(pay_type=1,1,0)) zfb_c,
sum(if(pay_type=2,1,0)) apple_c,
sum(if(device_type='android',1,0)) and_c,
sum(if(device_type='ios',1,0)) ios_c,
sum(if(order_status=1,real_fee,0)) total_money
from app_goods.app_order
where create_time>='#当前日期#' and create_time<date_add('#当前日期#',INTERVAL 1 day)
# 插入到报表
- replace into report_order(日期,用户数,订单总数,待支付数,已支付数,退款中数,已退款数,已关闭数,课程数,解锁码数,微信支付数,支付宝支付数,苹果支付数,安卓数,IOS数,实收总额)
values (:curr_date,:user_c,:order_c,:dzf_c,:yzf_c,:tkz_c,:ytk_c,:ygb_c,:kc_c,:jsm_c,:wx_c,:zfb_c,:apple_c,:and_c,:ios_c,:total_money)

使用yml简化多行sql语句案例的更多相关文章

  1. 如何对于几百行SQL语句进行优化?

    1.最近在开发中遇到的一些关于几百行SQL语句做查询的问题,需要如何的解决优化SQL这确实是个问题,对于当下的ORM 框架 EF 以及其他的一些的开源的框架例如Drapper ,以及Sqlite-Su ...

  2. 列表查询组件代码, 简化拼接条件SQL语句的麻烦

    列表查询组件代码, 简化拼接条件SQL语句的麻烦 多条件查询

  3. SqlSugar-执行Sql语句查询实例

    使用SqlSugar执行sql语句 1.简单查询 SqlSugarClient db = SugarContext.GetInstance(); //执行sql语句,处理 //1.执行sql,转成li ...

  4. Ibatis根据id获取拼接好的sql语句案例

    //得到sql语句: public virtual string GetSqlStatement(string statementName, object paramObject) { ISqlMap ...

  5. 多行SQL语句拼成一条数据

    将多条数据组合到一行 ) set @sql='select ''roleinfo:''' ) declare cursor1 cursor for select id from Userrole wh ...

  6. 谈谈SQL 语句的优化技术

    https://blogs.msdn.microsoft.com/apgcdsd/2011/01/10/sql-1/ 一.引言 一个凸现在很多开发者或数据库管理员面前的问题是数据库系统的性能问题.性能 ...

  7. 事务应用-运行多条SQL语句

    事务具有原子性,要么不运行,要么全运行,一旦成功运行永久保存.而这些正是因为事务的原子性和对数据库的持久性形成的.下面是一个关于统一给数据库中的数据改动的批量操作,利用到事务. TODO:批量改动数据 ...

  8. PL/SQL如何调试sql语句、存储过程

    一直以来,我总是在sql的工具,比如sql server.navicat等中执行sql语句来发现问题自己写的sql中的问题,结果被问起时,让人贻笑大方! 那么如何调试成白行的存储过程?如何调试成百行s ...

  9. Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析

    Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析 一.加载数据 import pandas as pd import numpy as np url = ('http ...

随机推荐

  1. Identity Server 4 从入门到落地(一)—— 从IdentityServer4.Admin开始

    最近项目中需要使用Identity Server 4,以前对这个技术只是有些了解,没有系统研究过,网上相关的资料不少,大多是从编写一个简单的认证服务开始,离能够落地使用有相当的距离,理论学习如何不结合 ...

  2. WebGoat8.2.2-A8不安全的反序列化

    1.概念   使用反序列化在各编程语言中略有不同,如Java.PHP.Python.Ruby.C/C++,但在关键概念上是一样的     序列化:将(内存中的)对象转化成数据格式,以便存储或传输   ...

  3. 详解如何用 CSS3 完成 3D transform变换

    Tips:阅读提示!!! 首先,本文针对的是3D transform变换的学习,所以你需要对 2D transform变换 有一定的了解 其次,需要说明的是,代码是一种需要自己不断实践的学科,建议各位 ...

  4. Codeforces 1149C - Tree Generator™(线段树+转化+标记维护)

    Codeforces 题目传送门 & 洛谷题目传送门 首先考虑这个所谓的"括号树"与直径的本质是什么.考虑括号树上两点 \(x,y\),我们不妨用一个"DFS&q ...

  5. Eigensoft-smartpca分析PCA报错:warning (mapfile): bad chrom: Segmentation fault

    目录 问题 解决 问题 一直以来用Eigensoft的smartpca来做群体遗传的PCA分析很顺畅,结果也比较靠谱. 但今天报错如下: $ ~/miniconda3/bin/smartpca -p ...

  6. 【机器学习与R语言】11- Kmeans聚类

    目录 1.理解Kmeans聚类 1)基本概念 2)kmeans运作的基本原理 2.Kmeans聚类应用示例 1)收集数据 2)探索和准备数据 3)训练模型 4)评估性能 5)提高模型性能 1.理解Km ...

  7. ubuntu终端颜色快速配置

    ubuntu终端颜色快速配置 根据以下step步骤设置即可 step1:备份:cp ~/.bashrc ~/.bashrc.backup step2:打开文件:vim ~/.bashrc step3: ...

  8. Java项目发现==顺手改成equals之后,会发生什么?

    最近发生一件很尴尬的事情,在维护一个 Java 项目的时候,发现有使用 == 来比较两个对象的属性, 于是顺手就把 == 改成了 equals.悲剧发生...... == 和 equals 的区别 = ...

  9. 26. Linux GIT

    windows git 下载链接: Msysgit   https://git-scm.com/download/win 1 进入git bash进行第一次配置 git config --global ...

  10. org.apache.hadoop.hive.ql.metadata.HiveException: Internal Error: cannot generate all output rows for a Partition解决

    自己在路径访问明细表开发时,写的sql如下 SELECT guid, sessionid, event['url'] as page, `timestamp` as ts, row_number() ...