使用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 ...
随机推荐
- [源码解析] PyTorch 分布式 Autograd (3) ---- 上下文相关
[源码解析] PyTorch 分布式 Autograd (3) ---- 上下文相关 0x00 摘要 我们已经知道 dist.autograd 如何发送和接受消息,本文再来看看如何其他支撑部分,就是如 ...
- Yii2 源码分析 入口文件执行流程
Yii2 源码分析 入口文件执行流程 1. 入口文件:web/index.php,第12行.(new yii\web\Application($config)->run()) 入口文件主要做4 ...
- R 语言 select函数在org.Hs.eg.db上的运用
首先org.Hs.eg.db是一个关于人类的 一,在R中导入包library(org.Hs.eg.db) http://www.bioconductor.org/packages/release/da ...
- 7. Minimum Depth of Binary Tree-LeetCode
难度系数:easy /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...
- 06 windows安装Python+Pycharm+Scrapy环境
windows安装Python+Pycharm+Scrapy环境 使用微信扫码关注微信公众号,并回复:"Python工具包",免费获取下载链接! 一.卸载python环境 卸载以下 ...
- SpringCloud微服务实战——搭建企业级开发框架(三十):整合EasyExcel实现数据表格导入导出功能
批量上传数据导入.数据统计分析导出,已经基本是系统必不可缺的一项功能,这里从性能和易用性方面考虑,集成EasyExcel.EasyExcel是一个基于Java的简单.省内存的读写Excel的开源项 ...
- day09搭建均衡负载和搭建BBS博客系统
day09搭建均衡负载和搭建BBS博客系统 搭建BBS博客系统 本次搭建bbs用到的技术 需要用到的: 1.Nginx+Django 2.Django+MySQL 环境准备 主机 IP 身份 db01 ...
- git删除了本地文件,从远程仓库中恢复
在本地删除了文件,使用git pull,无法从远程项目中拉取下来 具体操作 查看项目的状态,会显示出你删除的数据 git status 进入被删除的文件的目录下,假设删除的文件名为 test.txt ...
- OC-代理,字符串
总结 编号 标题 内容 一 protocol protocol 基本概念/语法格式/protocol和继承区别/使用注意/基协议/@required和@optional关键字/类型限制 二 代理设计模 ...
- zabbix之源码安装
#:官网地址 https://www.zabbix.com/documentation/4.0/zh/manual/installation/install #:解压并创建用户 root@ubuntu ...