mysql周报内容范文_Mysql各种报表查询含实例,日报,周报,月报,时间差自动计算...

public List retrieve(IReport report) {

List list = new ArrayList();

Map map = new HashMap();

// 设置结束日期

if (null != report.getEndTime()) {

map.put(ReportMeta.PROP_ENDTIME, report.getEndTime());

// 设置名称

if (null != report.getName()) {

map.put(ReportMeta.PROP_NAME, report.getName());

// 设置问题分类子项(必须有问题分类名称)

if (null != report.getQid() && report.getQid() > 0) {

map.put(ReportMeta.PROP_QID, report.getQid());

}

}

// 设置查询几周的数据,默认为本周,查询上周设置为:1L,依次类推

if (null == report.getQid()) {

report.setQid(0L);

}

}

String sql = "";

// 设置正负面的值

String tendency = "'正面','中性','负面-中','负面-高','负面-低'";

String hourarea = " " + dayhour + ":00:00";

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd" + hourarea);

if (map.size() > 0) {

// 日报数据查询

if ("daily".equals(report.getType())) {

sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "

+ "where end_time between date_add(:endTime,interval :dayHour hour_second) and :endTime";

// 日报正负面数据统计

} else if ("daily_tendency".equals(report.getType())) {

sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "

+ "where end_time between date_add(:endTime,interval :dayHour hour_second) "

+ "and :endTime and name in (:tendency)";

// 日报问题分类数据统计

} else if ("daily_question".equals(report.getType())) {

sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "

+ "where end_time between date_add(:endTime,interval :dayHour hour_second) and :endTime "

+ "and name in (select content from tbl_keyword where type = '问题分类' and "

+ "state = 'normal') order by quantity desc";

// 日报问题分类子类数据统计

} else if ("daily_question_child".equals(report.getType())) {

sql = "select name,quantity,start_time startTime,end_time endTime,qid,description,description2 from tbl_report "

+ "where end_time between date_add(:endTime,interval :dayHour hour_second) and :endTime "

+ "and name in (select content from tbl_keyword where type = '问题分类子类' and "

+ "state = 'normal') ";

// 日报数据查询(周一:上周五15:00~本周一15:00)

} else if ("daily_monday".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report "

+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "

+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) group by name";

// 日报正负面数据统计(周一:上周五15:00~本周一15:00)

} else if ("daily_tendency_monday".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report "

+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "

+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) and name in (:tendency) group by name";

// 日报问题分类数据统计(周一:上周五15:00~本周一15:00)

} else if ("daily_question_monday".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report "

+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "

+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) "

+ "and name in (select content from tbl_keyword where type = '问题分类' and "

+ "state = 'normal') group by name order by quantity desc";

// 日报问题分类子类数据统计(周一:上周五15:00~本周一15:00)

} else if ("daily_question_child_monday".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime,qid,description,description2 from tbl_report "

+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "

+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) "

+ "and name in (select content from tbl_keyword where type = '问题分类子类' and "

+ "state = 'normal') group by name";

// 周报每天数据

} else if ("weekly_day".equals(report.getType())) {

sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "

+ "where end_time between "

+ "(select date_sub(:endTime, interval weekday(:endTime) +:plusDay day)) "

+ "and (select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) "

+ "order by end_time";

// 周报所有数据汇总

} else if ("weekly_count".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) group by name";

// 周报正负面数据汇总

} else if ("weekly_count_tendency".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report where end_time between "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) and "

+ "name in (:tendency) group by name";

// 周报每天有效数据汇总(report.name="今日有效数据")

} else if ("weekly_count_valid".equals(report.getType())) {

// sql =

// "select '有效数据' name,sum(quantity) quantity,end_time endTime from tbl_report "

// +

// "where end_time between (select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) "

// +

// "and (select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) "

// +

// "and name in (:tendency) group by end_time order by end_time";

sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report where end_time between "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) "

+ "and (select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) "

+ "and name = :name group by endTime";

// 周报问题分类数据汇总

} else if ("weekly_count_question".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) and "

+ "name in (select content from tbl_keyword where type = '问题分类' and "

+ "state = 'normal') group by name";

// 周报问题分类子类数据汇总

} else if ("weekly_count_question_child".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,qid,description,description2 from tbl_report where end_time between "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "

+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) and "

+ "name in (select content from tbl_keyword where type = '问题分类子类' and "

+ "state = 'normal') group by name";

// 月报所用数据汇总

} else if ("monthly_count".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report where end_time between "

+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"

+ "interval +15 hour)) and (select date_add(last_day(:endTime),"

+ "interval +15 hour)) group by name";

// 月报正负面数据汇总

} else if ("monthly_count_tendency".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report where end_time between "

+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"

+ "interval +15 hour)) and (select date_add(last_day(:endTime),"

+ "interval +15 hour)) and name in (:tendency) group by name";

// 月报问题分类数据汇总

} else if ("monthly_count_question".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report where end_time between "

+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"

+ "interval +15 hour)) and (select date_add(last_day(:endTime),"

+ "interval +15 hour)) and name in (select content from tbl_keyword where type = '问题分类' and "

+ "state = 'normal') group by name";

// 月报问题分类子类数据汇总

} else if ("monthly_count_question_child".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,qid,description,description2,description3 from tbl_report where end_time between "

+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"

+ "interval +15 hour)) and (select date_add(last_day(:endTime),"

+ "interval +15 hour)) and name in (select content from tbl_keyword where type = '问题分类子类' and "

+ "state = 'normal') group by name";

} else if ("monthly_count_valid".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "

+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"

+ "interval +15 hour)) and (select date_add(last_day(:endTime),"

+ "interval +15 hour)) "

+ "and name = :name";

// 时间段查询正负面数据汇总

} else if ("duration_count_tendency".equals(report.getType())) {

sql = "select name,sum(quantity) quantity from tbl_report where end_time between "

+ ":startTime and :endTime and name in (:tendency) group by name";

// 时间段查询问题分类数据汇总

} else if ("duration_count_question".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "

+ ":startTime and :endTime and "

+ "name in (select content from tbl_keyword where type = '问题分类' and "

+ "state = 'normal') group by name";

// 时间段查询问题分类子类数据汇总

} else if ("duration_count_question_child".equals(report.getType())) {

sql = "select name,sum(quantity) quantity,qid,description,description2 from tbl_report where end_time between "

+ ":startTime and :endTime and "

+ "name in (select content from tbl_keyword where type = '问题分类子类' and "

+ "state = 'normal') group by name";

// 日报是否存在

} else if ("is_exists".equals(report.getType())) {

sql = "select name from tbl_report where end_time = :endTime";

}

sql = sql.replace(

":startTime",

"'"

+ (null != report.getStartTime() ? sdf

.format(report.getStartTime()) : "") + "'")

.replace(":endTime",

"'" + sdf.format(report.getEndTime()) + "'")

.replace(":dayHour", "'-23:59:59'").replace(":plusDay",

2 + (7 * report.getQid()) + "").replace(

":reduceDay", -4 + (7 * report.getQid()) + "")

.replace(":tendency", tendency).replace(

":name",

"'"

+ (null != report.getName() ? report

.getName() : "") + "'");

list = reportDao

.listQuery(sql, map, QueryStrType.SQL, Report.class);

}

return list;

}

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-04-12 11:28

浏览 7157

分类:数据库

评论

1 楼

123qqwe

2016-06-22

你确定,能被看懂!!!!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/264015.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

路由器01---k2刷Pandora

1.固件 固件(Firmware)就是写入EPROM(可擦写可编程只读存储器)或EEPROM(电可擦可编程只读存储器)中的程序。 对于独立可操作的电子产品,固件一般指它的操作系统(“担任着一个数码产品最基础、最底层工作的软件才可以称之为固件”&…

python中squeeze函数_详解pytorch中squeeze()和unsqueeze()函数介绍

squeeze的用法主要就是对数据的维度进行压缩或者解压。先看torch.squeeze() 这个函数主要对数据的维度进行压缩,去掉维数为1的的维度,比如是一行或者一列这种,一个一行三列(1,3)的数去掉第一个维数为一的维度之后就变成(3)行。squeeze(a)就是…

新闻网大数据实时分析可视化系统项目——7、Kafka分布式集群部署

Kafka是由LinkedIn开发的一个分布式的消息系统,使用Scala编写,它以可水平扩展和高吞吐率而被广泛使用。目前越来越多的开源分布式处理系统如Cloudera、Apache Storm、Spark都支持与Kafka集成。 1.下载Kafka并安装 1)下载Apache版本的Kafka。 …

关于Excel导入的问题记录

当Excel导入成为需要时,之前的导出Excel为html方式的方法就受阻了,于是,需要开始新的百度与google来解决问题。 前提为OLEDBExcel。 根据需求,多数是对于表的数据的导入。于是产生这么一个需求过程: 1。准备一个空的标…

AIX-vi操作-提示Unknown terminal type的问题解决方法

AIX-vi操作-提示Unknown terminal type的问题解决方法AIX Version 5.3$ vi /etc/profilelinux: Unknown terminal type[Hit return to continue] :q!I dont know what kind of terminal you are on - all I have is linux.[Using open mode]……临时办法,下次启动失…

Java性能调优工具

2019独角兽企业重金招聘Python工程师标准>>> 1、JDK命令行工具 1.1、jps命令 jps用于列出Java的进程,jps可以增加参数,-m用于输出传递给Java进程的参数,…

python3将字符串unicode转换为中文

在我们的python使用过程中,可能会遇到这样的情况: 我们得到的中文数据是unicode编码类型的,这在python中是没有问题的,可以直接打印显示为中文。 但是,如果我们需要和其它语言或前端进行交互或需要存到数据库中的时候&…

连接SQL Server文件集锦

在新建SqlConnection对象,连接资料库时连接失败,出现“常规网络错误。请检查您的网络文档。” DataSource直接写IP的话,通信协议是按照TCP/IP协议连接的,如果服务器端TCP/IP服务没有开启,则会报错“不允许远程连接” A…

python 波形发生_事件与信号

事件 Event所有的GUI程序都是事件驱动的。事件主要由用户触发,但也可能有其他触发方式:例如网络连接、window manager或定时器。当我们调用QApplication的exec_()方法时会使程序进入主循环。主循环会获取并分发事件。在事件模型中,有三个参与…

数据结构与算法6—树

树 树的表示方式有 树形图表示法:逻辑结构描述直观 嵌套集合表示法(文氏图表示法) 凹入表示法 广义表表示法 二叉树 二叉树是另一种重要的树形结构,是度为2的有序树,它的特点是每个结点至多有两棵子树。 二叉树的递归定义 二叉树…

LNMP一键安装包在安装完成后的一些安全设置

2019独角兽企业重金招聘Python工程师标准>>> 1.修改php.ini中的 base_dir 设定为:open_basedir/home/wwwroot/:/tmp/, 这样,脚本只能在wwwroot和tmp下读取。 2.设定权限,防止跨目录列表。 chown root:root wwwroot c…

docker基础应用

环境: centos 7 docker 19.03.0-beta3 192.168.10.10 关于如何安装docker请参考:https://www.cnblogs.com/caesar-id/p/10857312.html 1、查找合适的版本 [rootlocalhost ~]# docker search centos 2、下载centos镜像 [rootlocalhost ~]#docker pull c…

java 简单数据类型_java基本数据类型

基本数据类型JAVA中一共有八种基本数据类型,他们分别是byte、short、int、long、float、double、char、boolean类型型别字节取值范围byte整型1byte-27 ~ 27-1short整型2byte-215 ~ 215-1int整型4byte-231 ~ 231-1long整型8byte-263 ~ 263-1float浮点型4byte3.402823…

Win7中IIS7.0安装及ASP环境配置

打开控制面板中“程序”: “程序”中“打开或关闭Windows功能”: 如图,安装IIS7时需要选择要使用的功能模块: IIS7安装完成之后可以在开始菜单的所有程序中看到“管理工具”,其中有一个“Internet信息服务管理器”,如果没有可以按以下步骤…

java 3number_java 数据Number、Math

一个初出茅庐的小子与大家共享一些关于Number和Math的使用,因水平有限,难免有写的不完善的地方,嘻嘻。看完之后,希望可以留下你珍贵的指导意见。The Numbers Classes在写代码的时候,也许会使用到java各种的基本数据类型…

HOG(方向梯度直方图)

结合这周看的论文,我对这周研究的Histogram of oriented gradients(HOG)谈谈自己的理解: HOG descriptors 是应用在计算机视觉和图像处理领域,用于目标检測的特征描写叙述器。这项技术是用来计算局部图像梯度的方向信息的统计值。这样的方法跟边缘方向直…

保留数据给硬盘增加分区

我的块硬盘只有一个分区,里面还有数据,但是想再划分一个区,在win10系统下是这样操作的 首先,我的硬盘的文件系统是fat32,先通过命令提示符把文件系统转换成NTFS,转换前“压缩卷”是灰色的 convert c: /fs:n…

c# 简单序列化

序列化:是将对象状态转换为可保持或传输的格式的过程,原因有两个,第一是想永久的保存这些数据,以便将来可以重建这些数据。第二是想把数据从一个应用程序域发送到另外一个应用程序域中去。反序列化:就是把存储介质中的…

windows mobile开发循序渐进(6)windows mobile device center 使用问题

由于个人中邪,在经历一次windows 7安装失败之后,贼心不死,于昨天又重新安装了windows 7,终于成功。 回到windows mobile的开发上来呢,首先是配置环境,按照之前的经验,比较顺利的安装了virtual p…

mysql 代理 a_Keepalived+Mysql+Haproxy

#dd dd0 配主从vi /etc/my.cnf[mysqld]server-id 1log-bin mysql-binbinlog-ignore-db mysql,information_schemabinlog_format mixedauto-increment-increment 2auto-increment-offset 1#ddgrant replication slave on *.* to dd192.168.55.% identified by 123456show …