如何显示mysql表记录与连接3表?

7cwmlq89  于 2023-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(101)

我有3个表,分别是tb_injectiontemptb_injectiontb_notify_esim
以下是tb_injectiontemp的记录:
| 克纳奇德|地位|post_date2|
| - -----|- -----|- -----|
| 331293| 1| 2023 - 06 - 06 10:30:10|
| 331293| 1| 2023 - 06 - 06 10:43:13|
| 331293| 1| 2023 - 06 - 06 10:59:55|
| 331293| 1| 2023 - 06 - 06 12:06:35|
这些是tb_injection的记录:
| 唐加尔|克纳奇德|状态注入|idinject|
| - -----|- -----|- -----|- -----|
| 2023 - 06 - 06 10:33:03| 331293| 2| 0|
| 2023 - 06 - 06 10:45:04| 331293| 2| 0|
| 2023 - 06 - 06 11:04:04| 331293| 2| 0|
| 2023 - 06 - 06 12:07:03| 331293| 1| 2686028024114530|
这是tb_notify_esim的记录:
| idinject|创建于|
| - -----|- -----|
| 2686028024114530| 2023 - 06 - 06 12:07:21|
你能给我一个查询来获得这样的结果记录吗?
| 克纳奇德|post_date2| idinject|唐加尔|状态注入|创建于|
| - -----|- -----|- -----|- -----|- -----|- -----|
| 331293| 2023 - 06 - 06 12:06:35| 2686028024114530| 2023 - 06 - 06 12:07:03| 1| 2023 - 06 - 06 12:07:21|
| 331293| 2023 - 06 - 06 10:59:55| 0| 2023 - 06 - 06 11:04:04| 2|空值|
| 331293| 2023 - 06 - 06 10:43:13| 0| 2023 - 06 - 06 10:45:04| 2|空值|
| 331293| 2023 - 06 - 06 10:30:10| 0| 2023 - 06 - 06 10:33:03| 2|空值|
这是我的查询,但它仍然没有工作。

SELECT
  tb_injectiontemp.knackid,
  tb_injectiontemp.post_date2,
  tb_injection.idinject,
  tb_injection.tanggal,
  tb_injection.status as status_injection,
  tb_notify_esim.created_at
FROM
  tb_injectiontemp
JOIN
  tb_injection ON
    tb_injectiontemp.knackid = tb_injection.knackid
LEFT JOIN
  tb_notify_esim ON
    tb_injection.idinject = tb_notify_esim.idinject
WHERE tb_injection.knackid = 331293
GROUP BY tb_injection.tanggal 
ORDER BY
  tb_injection.tanggal DESC;

谢谢

t3psigkw

t3psigkw1#

这将工作。您在tb_injection.status中有一个错字,它应该是tb_injection.status。

SELECT
      tb_injectiontemp.knackid,
      tb_injectiontemp.post_date2,
      tb_injection.idinject,
      tb_injection.tanggal,
      tb_injection.status_injection as status_injection,
      tb_notify_esim.created_at
    FROM
      tb_injectiontemp
    JOIN
      tb_injection  ON
        tb_injectiontemp.knackid = tb_injection.knackid
    LEFT JOIN
      tb_notify_esim ON
        tb_injection.idinject = tb_notify_esim.idinject
    WHERE tb_injection.knackid = 331293
    GROUP BY tb_injection.tanggal 
    ORDER BY
      tb_injection.tanggal DESC;

相关问题