使用yml简化多行sql语句案例
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语句案例的更多相关文章
- 如何对于几百行SQL语句进行优化?
1.最近在开发中遇到的一些关于几百行SQL语句做查询的问题,需要如何的解决优化SQL这确实是个问题,对于当下的ORM 框架 EF 以及其他的一些的开源的框架例如Drapper ,以及Sqlite-Su ...
- 列表查询组件代码, 简化拼接条件SQL语句的麻烦
列表查询组件代码, 简化拼接条件SQL语句的麻烦 多条件查询
- SqlSugar-执行Sql语句查询实例
使用SqlSugar执行sql语句 1.简单查询 SqlSugarClient db = SugarContext.GetInstance(); //执行sql语句,处理 //1.执行sql,转成li ...
- Ibatis根据id获取拼接好的sql语句案例
//得到sql语句: public virtual string GetSqlStatement(string statementName, object paramObject) { ISqlMap ...
- 多行SQL语句拼成一条数据
将多条数据组合到一行 ) set @sql='select ''roleinfo:''' ) declare cursor1 cursor for select id from Userrole wh ...
- 谈谈SQL 语句的优化技术
https://blogs.msdn.microsoft.com/apgcdsd/2011/01/10/sql-1/ 一.引言 一个凸现在很多开发者或数据库管理员面前的问题是数据库系统的性能问题.性能 ...
- 事务应用-运行多条SQL语句
事务具有原子性,要么不运行,要么全运行,一旦成功运行永久保存.而这些正是因为事务的原子性和对数据库的持久性形成的.下面是一个关于统一给数据库中的数据改动的批量操作,利用到事务. TODO:批量改动数据 ...
- PL/SQL如何调试sql语句、存储过程
一直以来,我总是在sql的工具,比如sql server.navicat等中执行sql语句来发现问题自己写的sql中的问题,结果被问起时,让人贻笑大方! 那么如何调试成白行的存储过程?如何调试成百行s ...
- Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析
Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析 一.加载数据 import pandas as pd import numpy as np url = ('http ...
随机推荐
- distmat 计算遗传距离
distmat 可用于计算遗传距离,得到距离矩阵 1 在线运算 可通过在线进行遗传距离的计算,网址:http://www.bioinformatics.nl/cgi-bin/emboss/distma ...
- 2基因组间鉴定SV
本文学习费章军老师文章Genome of Solanum pimpinellifolium provides insights into structural variants during toma ...
- 比对软件Blast,Blast+,Diamond比较
1. Blast (1)格式化数据库 formatdb -i db.seq -p T -o T -l logfile 主要参数: -i 输入需要格式化的源数据库名称 -p 文件类型,是核苷酸序列数据库 ...
- MISA(在线)注释叶绿体基因组SSR
SSR (Simple Sequence Repeat),即简单重复序列,是一种以PCR技术为核心的DNA分子标记技术,也称为微卫星序列或者串联重复. 简单重复顾名思义就是以很短的序列为一个单元,比如 ...
- R包开发过程记录
目的 走一遍R包开发过程,并发布到Github上使用. 步骤 1. 创建R包框架 Rsutdio --> File--> New Project--> New Directory - ...
- 进程和线程操作系统转载的Mark一下
https://www.cnblogs.com/leisure_chn/p/10393707.html Linux的进程线程及调度 本文为宋宝华<Linux的进程.线程以及调度>学习笔记. ...
- KEPServeEX 6与KepOPC中间件测试
KEPServeEX 6可以组态服务器端和客户端连接很多PLC以及具有OPC服务器的设备,以下使用KEPServeEX 6建立一个OPC UA服务器,然后使用KepOPC建立客户端来连接服务器做测试. ...
- A Child's History of England.37
Many other noblemen repeating and supporting this when it was once uttered, Stephen and young Planta ...
- Android 利用Settings.Global属性跨应用定义标志位
https://blog.csdn.net/ouzhuangzhuang/article/details/82258148 需求 需要在不同应用中定义一个标志位,这里介绍下系统级别的应用和非系统级别应 ...
- linux修改文件权限命令
先看个实例: [root@local opt]#ls -al ls -al 命令是列出目录的所有文件,包括隐藏文件.隐藏文件的文件名第一个字符为'.' -rw-r--r-- 1 root root ...