开发者

cross table from two tables in MySql

I have two tables, one is *parts_raised* and another is *parts_detail*.

parts_raised:

SN(int),Job_Number(int),Category(varchar),Part_code(int),technician(varchar),Time      (timestamp),

Parts_detail:

Part_code(int),Value(int),Descriptions(text),

part_code is same in both table.

How can I write query for achieving total count of jobs,and their total c开发者_开发问答ost per technician on daily basis.

technician    day1                             day2            
              Total Jobs     total cost        Total Jobs     total cost   

Technician-1  4                 153              5              253
Technician-2  7                 352              2              256

How can achieve this or suggest any other method for getting same result?


Does this do it?

SELECT
  technician, Job_day, SUM(Value)
FROM
(
  SELECT
    pr.technician, DAY(pr.Time) AS Job_day, pd.Value 
  FROM
    parts_raised AS pr
  JOIN
    Parts_detail AS pd
  ON
    pd.Part_code = pr.Part_code
) AS tempId
GROUP BY
  technician, Job_day
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜