2018-12-28 SQL

SELECT
orit.pdt_name as '商品名称',
orit.pdt_code as '商品编码',
pc.category_name as '商品分类',
orit.market_price as '参考价格',
SUM(orit.qty) as '销售量件数',
SUM(orit.row_total - divide_order_discount_amount) as '付款金额',
count(distinct orit.order_sn) as '订单数',
count(distinct orif.user_id) as '买家数'
FROM
order_item orit
LEFT JOIN
order_info orif on orif.order_sn = orit.order_sn
LEFT JOIN
product_info pg ON orit.product_id = pg.product_id
LEFT JOIN
shop_category pc on pg.category_id = pc.id
WHERE orit.shop_id='193'
GROUP BY orit.pdt_name

-- -- 登记次数
-- SELECT
-- CONCAT(u.lastname , u.firstname) as '姓名' ,
-- count(te.user_id) as '登记次数'
-- -- DATE_FORMAT(te.updated_on,'%Y%m%d') days as '登记天数'
-- from redmine.time_entries te,
-- redmine.users u
-- where
-- te.user_id = u.id
-- and te.updated_on >= date_sub(NOW() , interval 60 day)
-- GROUP BY te.user_id

-- 登记天数
-- SELECT z.username as '姓名',
-- COUNT(z.username) as '登记天数'
-- FROM
-- (
-- SELECT
-- DISTINCT CONCAT(u.lastname , u.firstname) as username ,
-- -- COUNT(te.user_id) as "登记天数",
-- DATE_FORMAT(te.created_on,'%Y%m%d') as days
-- from redmine.time_entries te,
-- redmine.users u
-- where
-- te.user_id = u.id
-- and te.updated_on >= date_sub(NOW() , interval 30 day)
-- ) z
-- GROUP BY z.username

-- 工时平均登录值
-- SELECT
-- CONCAT(u.lastname , u.firstname) as '姓名' ,
-- max(te.hours) as '最大登记值',
-- AVG(te.hours) as '工时平均登记值'
-- from redmine.time_entries te,
-- redmine.users u
-- where
-- te.user_id = u.id
-- and te.updated_on >= date_sub(NOW() , interval 60 day)
-- group by
-- te.user_id

-- bug指出量,任务创建量
-- SELECT
-- CONCAT(u.lastname, u.firstname) AS '名字',
-- t1.bug_sum AS '指出BUG数',
-- t2.bug_sum AS '创建任务数'
-- FROM redmine.users u
-- INNER JOIN (
-- SELECT i.author_id, COUNT(i.author_id) AS 'bug_sum'
-- FROM redmine.issues i
-- WHERE i.tracker_id = 1
-- AND i.created_on >= date_sub(NOW(), INTERVAL 30 DAY)
-- GROUP BY i.author_id
-- ) t1
-- ON u.id = t1.author_id
-- INNER JOIN (
-- SELECT i.author_id, COUNT(i.author_id) AS 'bug_sum'
-- FROM redmine.issues i
-- INNER JOIN redmine.users u ON u.id = i.author_id
-- WHERE i.created_on >= date_sub(NOW(), INTERVAL 30 DAY) and i.tracker_id != 1
-- GROUP BY i.author_id
-- ) t2
-- ON u.id = t2.author_id
-- ORDER BY t1.bug_sum DESC limit 4

-- 工作效率
-- SELECT
-- t1.user_name as '姓名' ,
-- t1.hours as '总工时' ,
-- t2.estimated_hours as '总预计' ,
-- (t1.hours / t2.estimated_hours) as '效率'
-- FROM
-- (
-- SELECT
-- u.id AS user_id ,
-- CONCAT(u.lastname , u.firstname) AS user_name ,
-- SUM(te.hours) AS hours
-- FROM
-- redmine.time_entries te ,
-- redmine.users u
-- WHERE
-- te.user_id = u.id
-- AND te.updated_on <= NOW()
-- AND te.updated_on >= date_sub(NOW() , INTERVAL 30 DAY)
-- GROUP BY
-- u.id
-- ORDER BY
-- SUM(te.hours) DESC
-- ) t1
-- INNER join(
-- SELECT
-- i.assigned_to_id AS user_id ,
-- sum(i.estimated_hours) as estimated_hours
-- FROM
-- redmine.issues i
-- WHERE
-- i.id IN(
-- SELECT
-- te.issue_id
-- FROM
-- redmine.time_entries te
-- WHERE
-- te.updated_on <= NOW()
-- AND te.updated_on >= date_sub(NOW() , INTERVAL 30 DAY)
-- )
-- GROUP BY
-- i.assigned_to_id
-- ) t2 on t1.user_id = t2.user_id
-- order by
-- t1.hours desc

-- 逾期未解决任务数
-- select
-- t1.username as '姓名',
-- t1.all_count as '总数',
-- IFNULL(t2.fixed_count, 0) as '解决数',
-- t1.all_count - IFNULL(t2.fixed_count, 0) as '逾期未解决任务数'
-- from
-- (
-- select
-- u.id as user_id ,
-- CONCAT(u.lastname , u.firstname) as 'username' ,
-- count(i.assigned_to_id) as 'all_count'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.due_date <= date_add(NOW() , interval - 1 day)
-- and i.status_id in(1 , 2 , 3 , 4)
-- GROUP BY
-- i.assigned_to_id
-- ) t1
-- left join(
-- select
-- u.id as user_id ,
-- CONCAT(u.lastname , u.firstname) as 'username' ,
-- count(i.assigned_to_id) as 'fixed_count'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.due_date <= date_add(NOW() , interval - 1 day)
-- and i.status_id in(3)
-- GROUP BY
-- i.assigned_to_id
-- ) t2 on t1.user_id = t2.user_id
-- order by
-- t1.all_count desc

-- bug解决率
-- select
-- t1.user_name as '姓名' ,
-- t1.bug_sum as '总BUG' ,
-- t2.fixed_bug_sum as '解决量',
-- t3.work_sum as '总任务',
-- IFNULL(t2.fixed_bug_sum,0) / t1.bug_sum as 'bug解决率'
-- from
-- (
-- select
-- u.id as 'user_id' ,
-- CONCAT(u.lastname , u.firstname) as 'user_name' ,
-- count(i.assigned_to_id) as 'bug_sum'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.tracker_id = 1
-- and i.created_on >= date_sub(NOW() , interval 60 day)
-- GROUP BY
-- i.assigned_to_id
-- ORDER BY
-- count(i.assigned_to_id) desc
-- ) as t1 ,
-- (
-- select
-- u.id as 'user_id' ,
-- CONCAT(u.lastname , u.firstname) as 'user_name' ,
-- count(i.assigned_to_id) as 'fixed_bug_sum'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.tracker_id = 1
-- and i.status_id not in(1 , 2)
-- and i.created_on >= date_sub(NOW() , interval 60 day)
-- GROUP BY
-- i.assigned_to_id
-- ORDER BY
-- count(i.assigned_to_id) desc
-- ) as t2 ,
-- (
-- select
-- u.id as 'user_id' ,
-- CONCAT(u.lastname , u.firstname) as 'user_name' ,
-- count(i.assigned_to_id) as 'work_sum'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.tracker_id != 1
-- and i.created_on >= date_sub(NOW() , interval 60 day)
-- GROUP BY
-- i.assigned_to_id
-- ) t3
-- where
-- t1.user_id = t2.user_id
-- and t2.user_id = t3.user_id
-- order by
-- t1.bug_sum desc

-- 任务量,bug量 ,任务完成率
-- select
-- t1.user_name as '姓名' ,
-- t1.work_sum as '总任务' ,
-- t2.fixed_work_sum as '完成量',
-- t3.bug_sum as '总bug',
-- IFNULL(t2.fixed_work_sum,0) / t1.work_sum AS '任务完成率'
-- from
-- (
-- select
-- u.id as 'user_id' ,
-- CONCAT(u.lastname , u.firstname) as 'user_name' ,
-- count(i.assigned_to_id) as 'work_sum'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.tracker_id != 1
-- and i.created_on >= date_sub(NOW() , interval 60 day)
-- GROUP BY
-- i.assigned_to_id
-- ORDER BY
-- count(i.assigned_to_id) desc
-- ) as t1 ,
-- (
-- select
-- u.id as 'user_id' ,
-- CONCAT(u.lastname , u.firstname) as 'user_name' ,
-- count(i.assigned_to_id) as 'fixed_work_sum'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.tracker_id != 1
-- and i.status_id not in(1 , 2)
-- and i.created_on >= date_sub(NOW() , interval 60 day)
-- GROUP BY
-- i.assigned_to_id
-- ORDER BY
-- count(i.assigned_to_id) desc
-- ) as t2 ,(select
-- u.id as 'user_id' ,
-- CONCAT(u.lastname , u.firstname) as 'user_name' ,
-- count(i.assigned_to_id) as 'bug_sum'
-- from
-- redmine.issues i ,
-- redmine.users u
-- where
-- u.id = i.assigned_to_id
-- and i.tracker_id = 1
-- and i.created_on >= date_sub(NOW() , interval 60 day)
-- GROUP BY
-- i.assigned_to_id
-- ORDER BY
-- count(i.assigned_to_id) desc)t3
-- where
-- t1.user_id = t2.user_id and t2.user_id=t3.user_id
-- order by
-- t1.work_sum desc

-- bug 占时指数
SELECT
CONCAT(u.lastname, u.firstname) AS '姓名',
-- IFNULL(t2.hours,0) AS 'Bug总工时',
-- t1.hours - IFNULL(t2.hours,0) AS '非Bug总工时',
-- t1.hours AS '总工时',
IFNULL(t2.hours,0) / t1.hours AS 'Bug指数'
FROM redmine.users u
LEFT JOIN (
SELECT te.user_id, SUM(te.hours) AS hours
FROM redmine.time_entries te
WHERE te.updated_on >= date_sub(NOW(), INTERVAL 60 DAY)
GROUP BY te.user_id
) t1
ON t1.user_id = u.id
LEFT JOIN (
SELECT te.user_id, SUM(te.hours) AS hours
FROM redmine.time_entries te
INNER JOIN redmine.issues iu ON te.issue_id = iu.id
WHERE iu.tracker_id = 1
AND te.updated_on >= date_sub(NOW(), INTERVAL 60 DAY)
GROUP BY te.user_id
) t2
ON t2.user_id = u.id
WHERE t1.hours > 0

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,290评论 6 491
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,107评论 2 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,872评论 0 347
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,415评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,453评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,784评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,927评论 3 406
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,691评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,137评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,472评论 2 326
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,622评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,289评论 4 329
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,887评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,741评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,977评论 1 265
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,316评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,490评论 2 348

推荐阅读更多精彩内容

  • 50个常用的sql语句Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname...
    哈哈海阅读 1,226评论 0 7
  • //www.greatytc.com/p/55755fc649b1http://homepages.in...
    GoDeep阅读 182评论 0 0
  • 如何保持心动、如何爱别人同时更“爱自己”,节选自赖佩霞的著作《我要心动一辈子》中“心动箴言”,或许可以给你一些启迪...
    璞学苑阅读 802评论 0 0
  • 姓名曹彩萍~公司丹阳明煌工具。 日精进打卡第 46天 《六项精进》1遍 《大学》...
    曹彩萍阅读 155评论 0 0