wdate-year-month-week-gategory-amount-coin
---2016-12-02 19:46:39
the whole table
DISTINCT field
SUM(field)
COUNT(field)
--- 888983 rows OK
SELECT
*
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
SUM(coin) AS month_category_coin,
SUM(amount) AS month_category_amount,
country AS fk_country,
category AS fk_category
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
history_year,
history_month
) AS wt_month_sum
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_asin) AS month_category_diff_asins
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
country AS fk_country,
category AS fk_category,
asin AS fk_asin
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_asin,
history_year,
history_month
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month
) AS wt_month_diff_asins ON wt_month_sum.fk_country = wt_month_diff_asins.fk_country
AND wt_month_sum.fk_category = wt_month_diff_asins.fk_category
AND wt_month_sum.history_year = wt_month_diff_asins.history_year
AND wt_month_sum.history_month = wt_month_diff_asins.history_month
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_diff_days) AS month_category_diff_days
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
country AS fk_country,
category AS fk_category,
date AS fk_diff_days
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_diff_days,
history_year,
history_month
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month
) AS wt_month_diff_days ON wt_month_sum.fk_country = wt_month_diff_days.fk_country
AND wt_month_sum.fk_category = wt_month_diff_days.fk_category
AND wt_month_sum.history_year = wt_month_diff_days.history_year
AND wt_month_sum.history_month = wt_month_diff_days.history_month
LEFT JOIN (
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
DATE_FORMAT(date, '%V') AS history_week,
SUM(coin) AS week_category_coin,
SUM(amount) AS week_category_amount,
country AS fk_country,
category AS fk_category
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
history_year,
history_month,
history_week
) AS wt_week_sum ON wt_month_sum.fk_country = wt_week_sum.fk_country
AND wt_month_sum.fk_category = wt_week_sum.fk_category
AND wt_month_sum.history_year = wt_week_sum.history_year
AND wt_month_sum.history_month = wt_week_sum.history_month
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.history_week,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_diff_asin) AS week_category_diff_asins
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
DATE_FORMAT(date, '%V') AS history_week,
country AS fk_country,
category AS fk_category,
asin AS fk_diff_asin
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_diff_asin,
history_year,
history_month,
history_week
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month,
history_week
) AS wt_week_diff_asins ON wt_week_sum.fk_country = wt_week_diff_asins.fk_country
AND wt_week_sum.fk_category = wt_week_diff_asins.fk_category
AND wt_week_sum.history_year = wt_week_diff_asins.history_year
AND wt_week_sum.history_month = wt_week_diff_asins.history_month
AND wt_week_sum.history_week = wt_week_diff_asins.history_week
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.history_week,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_diff_days) AS week_category_diff_days
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
DATE_FORMAT(date, '%V') AS history_week,
country AS fk_country,
category AS fk_category,
date AS fk_diff_days
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_diff_days,
history_year,
history_month,
history_week
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month,
history_week
) AS wt_week_diff_days ON wt_week_sum.fk_country = wt_week_diff_days.fk_country
AND wt_week_sum.fk_category = wt_week_diff_days.fk_category
AND wt_week_sum.history_year = wt_week_diff_days.history_year
AND wt_week_sum.history_month = wt_week_diff_days.history_month
AND wt_week_sum.history_week = wt_week_diff_days.history_week
SELECT COUNT(DISTINCT date),COUNT(DISTINCT asin), SUM(coin),SUM(amount),SUM(coin)/SUM(amount) FROM asinsaleranks WHERE category=9 AND LEFT(date, 6) = ''
SELECT COUNT(DISTINCT date),COUNT(DISTINCT asin), SUM(coin),SUM(amount),SUM(coin)/SUM(amount) FROM asinsaleranks WHERE category=9 AND LEFT(date, 6) = '' SELECT COUNT(DISTINCT date),COUNT(DISTINCT asin), SUM(coin),SUM(amount),SUM(coin)/SUM(amount) FROM asinsaleranks WHERE category=6 AND date= ''
SELECT COUNT(DISTINCT date),COUNT(DISTINCT asin), SUM(coin),SUM(amount),SUM(coin)/SUM(amount) FROM asinsaleranks WHERE category=6 AND date> '' AND date< ''
SELECT COUNT(DISTINCT date),COUNT(DISTINCT asin), SUM(coin),SUM(amount),SUM(coin)/SUM(amount) FROM asinsaleranks WHERE category=6 AND date> '' AND date< ''
SELECT
*
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
SUM(coin) AS month_category_coin,
SUM(amount) AS month_category_amount,
country AS fk_country,
category AS fk_category
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
history_year,
history_month
) AS wt_month_sum
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_asin) AS month_category_diff_asins
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
country AS fk_country,
category AS fk_category,
asin AS fk_asin
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_asin,
history_year,
history_month
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month
) AS wt_month_diff_asins ON wt_month_sum.fk_country = wt_month_diff_asins.fk_country
AND wt_month_sum.fk_category = wt_month_diff_asins.fk_category
AND wt_month_sum.history_year = wt_month_diff_asins.history_year
AND wt_month_sum.history_month = wt_month_diff_asins.history_month
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_diff_days) AS month_category_diff_days
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
country AS fk_country,
category AS fk_category,
date AS fk_diff_days
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_diff_days,
history_year,
history_month
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month
) AS wt_month_diff_days ON wt_month_sum.fk_country = wt_month_diff_days.fk_country
AND wt_month_sum.fk_category = wt_month_diff_days.fk_category
AND wt_month_sum.history_year = wt_month_diff_days.history_year
AND wt_month_sum.history_month = wt_month_diff_days.history_month
LEFT JOIN (
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
DATE_FORMAT(date, '%V') AS history_week,
SUM(coin) AS week_category_coin,
SUM(amount) AS week_category_amount,
country AS fk_country,
category AS fk_category
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
history_year,
history_month,
history_week
) AS wt_week_sum ON wt_month_sum.fk_country = wt_week_sum.fk_country
AND wt_month_sum.fk_category = wt_week_sum.fk_category
AND wt_month_sum.history_year = wt_week_sum.history_year
AND wt_month_sum.history_month = wt_week_sum.history_month
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.history_week,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_diff_asin) AS week_category_diff_asins
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
DATE_FORMAT(date, '%V') AS history_week,
country AS fk_country,
category AS fk_category,
asin AS fk_diff_asin
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_diff_asin,
history_year,
history_month,
history_week
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month,
history_week
) AS wt_week_diff_asins ON wt_week_sum.fk_country = wt_week_diff_asins.fk_country
AND wt_week_sum.fk_category = wt_week_diff_asins.fk_category
AND wt_week_sum.history_year = wt_week_diff_asins.history_year
AND wt_week_sum.history_month = wt_week_diff_asins.history_month
AND wt_week_sum.history_week = wt_week_diff_asins.history_week
LEFT JOIN (
SELECT
tmp.history_year,
tmp.history_month,
tmp.history_week,
tmp.fk_country,
tmp.fk_category,
COUNT(fk_diff_days) AS week_category_diff_days
FROM
(
SELECT
DATE_FORMAT(date, '%Y') AS history_year,
DATE_FORMAT(date, '%m') AS history_month,
DATE_FORMAT(date, '%V') AS history_week,
country AS fk_country,
category AS fk_category,
date AS fk_diff_days
FROM
study_test
WHERE
DATE_FORMAT(date, '%Y') = 2016
GROUP BY
fk_country,
fk_category,
fk_diff_days,
history_year,
history_month,
history_week
) AS tmp
GROUP BY
fk_country,
fk_category,
history_year,
history_month,
history_week
) AS wt_week_diff_days ON wt_week_sum.fk_country = wt_week_diff_days.fk_country
AND wt_week_sum.fk_category = wt_week_diff_days.fk_category
AND wt_week_sum.history_year = wt_week_diff_days.history_year
AND wt_week_sum.history_month = wt_week_diff_days.history_month
AND wt_week_sum.history_week = wt_week_diff_days.history_week
DROP TABLE IF EXISTS `study_test`;
CREATE TABLE `study_test` (
`country` char(2) COLLATE utf8_bin NOT NULL,
`date` char(8) COLLATE utf8_bin NOT NULL DEFAULT '',
`asin` char(10) COLLATE utf8_bin NOT NULL,
`category` int(10) unsigned NOT NULL DEFAULT '',
`coin` decimal(16,4) unsigned NOT NULL DEFAULT '0.0000',
`amount` decimal(16,4) unsigned NOT NULL DEFAULT '0.0000',
PRIMARY KEY (`country`,`date`,`asin`),
KEY `k_asin` (`asin`) USING BTREE,
KEY `k_coin` (`coin`) USING BTREE,
KEY `k_amount` (`amount`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
wdate-year-month-week-gategory-amount-coin的更多相关文章
- T-SQL - 习题02_将数据表year|month|amount查询成year|m1|m2|m3|m4的样式
时间:2017-09-11 整理:byzqy 题目:有个年度统计表,结构如下: 怎么样把这个表,查询成这样一个结果: 这是在面试过程中遇到的一个关于数据库的题,没有一点思路,不知它考查到的知识点是什么 ...
- [Swift]LeetCode518. 零钱兑换 II | Coin Change 2
You are given coins of different denominations and a total amount of money. Write a function to comp ...
- Give $20/month and provide 480 hours of free education
Hi , Hope all is well. Summer is right around the corner, and the Khan Academy team is excited to sp ...
- Kotlin 介绍
Kotlin (0:00) 大家好,我是 Michael Pardo,今天我要给大家展示一下 Kotlin 这门语言,同时看看他如何让你在 Android 开发的时候更开心,更有效率. Kotlin ...
- oracle 触发器学习
触发器使用教程和命名规范 目 录触发器使用教程和命名规范 11,触发器简介 12,触发器示例 23,触发器语法和功能 34,例一:行级触发器之一 45,例二:行级触发器之二 46,例三:INSTEA ...
- SSH三大框架笔面试总结
Java工程师(程序员)面题 Struts,Spring,Hibernate三大框架 1.Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建Sess ...
- Oracle触发器实例(网搜)
触发器使用教程和命名规范 目 录触发器使用教程和命名规范 11,触发器简介 12,触发器示例 23,触发器语法和功能 34,例一:行级触发器之一 45,例二:行级触发器之二 46,例三:INSTEA ...
- 关于完整解答Leo C.W博客中名为“我们公司的ASP.NET 笔试题,你觉得难度如何”的所有题目
关于完整解答Leo C.W博客中名为“我们公司的ASP.NET 笔试题,你觉得难度如何”的所有题目,请大家鉴定,不足之处,敬请指教! 第1到3题解答如下: public enum QuestionTy ...
- mysql 经典题目
题目1:实现如下效果 CREATE TABLE IF NOT EXISTS tb_amount( `Id` INT NOT NULL AUTO_INCREMENT, `), `), `Amount` ...
- How to do Mathematics
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:匿名用户链接:http://www.zhihu.com/question/30087053/answer/47815698来源 ...
随机推荐
- PHP CI框架学习笔记-分页实现程序
视图html <div id="body"> <form action="/index.php/search/index/" method= ...
- 蒟蒻的树形dp记录
POJ2342: 题意:某公司要举办一次晚会,但是为了使得晚会的气氛更加活跃,每个参加晚会的人都不希望在晚会中见到他的直接上司,现在已知每个人的活跃指数和上司关系(当然不可能存在环),求邀请哪些人(多 ...
- android 自定义弹出框AlertDialog ,很炫的哦
于是就小小的模仿了下自己写了这个这样的效果,主要代码如下:dlg = new AlertDialog.Builder(context).create();dlg.show();dlg.getWin ...
- Activity启动方式
Activity启动方式有四种,分别是: standard singleTop singleTask singleInstance 可以根据实际的需求为Activity设置对应的启动模式,从而可以避免 ...
- AsyncTask下载JSON
public class HttpUtils { // 从网络url上下载字符串 public static String getHttpStr(String url) { HttpClient ht ...
- Java 完美判断中文字符
Java判断一个字符串是否有中文一般情况是利用Unicode编码(CJK统一汉字的编码区间:0x4e00–0x9fbb)的正则来做判断,但是其实这个区间来判断中文不是非常精确,因为有些中文的标点符号比 ...
- WPF的Presenter(ContentPresenter)(转)
这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- 4.1 avd
6.接着我们回到文件夹界面,运行 AVD Manager.exe. 7.打开 AVD Manager.exe后,点击“New"创建新的模拟器: 8.创建一个新的 Android Virtua ...
- Centos6.4 yum安装MariaDB5.5
vi /etc/yum.repos.d/MariaDB.repo 加入下面内容 [mariabd]name=MariaDBbaseurl=http://yum.mariadb.org/5.5.34/c ...