MySql 中两个表的交叉表

发布于 2024-09-26 03:32:38 字数 733 浏览 2 评论 0原文

我有两张表,一张是 *parts_raised*,另一张是 *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 相同。

我如何编写查询来实现作业总数以及每个技术人员每天的总成本。

technician    day1                             day2            
              Total Jobs     total cost        Total Jobs     total cost   

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

如何实现这一目标或建议任何其他方法来获得相同的结果?

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 cost 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末染殇 2024-10-03 03:32:38

这个有作用吗?

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文