使用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 ...
随机推荐
- AWS EKS 添加IAM用户角色
作者:SRE运维博客 博客地址: https://www.cnsre.cn/ 文章地址:https://www.cnsre.cn/posts/211203931498/ 相关话题:https://ww ...
- R语言与医学统计图形【8】颜色的选取
R语言基础绘图系统 基础绘图包之低级绘图函数--内置颜色. 1.内置颜色选取 功能657种内置颜色.colors() 调色板函数:palette(), rgb(), rainbow(). palett ...
- requests+bs4爬取豌豆荚排行榜及下载排行榜app
爬取排行榜应用信息 爬取豌豆荚排行榜app信息 - app_detail_url - 应用详情页url - app_image_url - 应用图片url - app_name - 应用名称 - ap ...
- python爬虫采集
python爬虫采集 最近有个项目需要采集一些网站网页,以前都是用php来做,但现在十分流行用python做采集,研究了一些做一下记录. 采集数据的根本是要获取一个网页的内容,再根据内容筛选出需要的数 ...
- 巩固javaweb的第二十一天
巩固内容:对输入信息进行验证 JavaScript 语言 在 Web 应用中需要在客户端执行的功能可以使用 JavaScript 语言编写,在使用的时候 需要把 JavaScript 代码放在下面的两 ...
- JVM结构详解
JVM 结构详解 JVM 结构图 程序计数器(PC 寄存器) 程序计数器的定义 程序计数器是一块较小的内存空间,是当前线程正在执行的那条字节码指令的地址.若当前线程正在执行的是一个本地方法,那么此时程 ...
- 疯了吧!这帮人居然用 Go 写“前端”?(二)
作者 | 郑嘉涛(羣青) 来源|尔达 Erda 公众号 前言 上篇我们讲了故事发生的背景,也简单阐述了组件及协议的设想: 一.丰富的通用组件库. 二.组件渲染能力,将业务组件渲染成通用组件 ...
- adhere, adjust, adjacent
adhere to stick,不是to here. 在古英语里,stick是twig(细树枝).fasten(想必是用twig来固定).后引申为粘住.stick还有stab, pierce的意思,想 ...
- absent, absolute
absent 1. A teacher asked in a class who killed Abraham Lincoln. A blonde said "It wasn't me, I ...
- D3学习-加载本地数据
在加载本地数据时,弄了很久都无法显示出来,后来才知道是要把数据文件和html文件都加载到服务器上面 这样就可以显示出来了,