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