gpt4 book ai didi

MySQL Join 结果错误

转载 作者:行者123 更新时间:2023-11-29 12:08:37 25 4
gpt4 key购买 nike

我有一个关于 JOIN 的简单问题。这是我的查询:

SELECT
products.name AS name,
products.last_scanned AS last_scanned,
products.last_scanned AS last_changed,

ph.price AS price,
ph.mirror_price AS mirror_price,
ph.change_date AS change_date,

ph.dioPlusZapPrice AS dioPlusZapPrice,
ph.dioPlusSitePrice AS dioPlusSitePrice,

ph.inkDepotZapPrice AS inkDepotZapPrice,
ph.inkDepotSitePrice AS inkDepotSitePrice,

ph.misradiaZapPrice AS misradiaZapPrice,
ph.misradiaSitePrice AS misradiaSitePrice,

ph.netPrintZapPrice AS netPrintZapPrice,
ph.netPrintSitePrice AS netPrintSitePrice,

img1.image_blob AS dioPlusImage,
img2.image_blob AS inkDepotImage,
img3.image_blob AS misradiaImage,
img4.image_blob AS netPrintImage

FROM
price_history ph

LEFT JOIN products ON products.productID=ph.productID

LEFT JOIN imagedata img1 ON img1.id = ph.imagename_dioPlus
LEFT JOIN imagedata img2 ON img2.id = ph.imagename_inkDepot
LEFT JOIN imagedata img3 ON img3.id = ph.imagename_misradia
LEFT JOIN imagedata img4 ON img4.id = ph.imagename_netPrint

ORDER BY ph.change_date DESC

该查询的结果是:

Brother MFC-L2700DW|2015-06-26 15:47|2015-06-26 15:47|949|949|2015-06-26 15:47|949|949|969|999|0|0|0|0|[BLOB - 217.9 KiB]|[BLOB - 217.9 KiB]|NULL|NULL

显示相同的 Blob 。

这是我的 imagadata 表:

+----+-----------+------------+---------------------------------------+
| ID | image_blob | ID | imagename |
+----+-----------+-----+----------------------------------------------+
| 1 | [BLOB - 19.5 KiB] | 1 | a5052c6e-1120-4ece-994d-2cdac7e7baa4 |
| 2 | [BLOB - 217.9 KiB] | 2 | 1ed6f935-a44a-4f07-9c6b-fa51da5d4bdb |
| 3 | [BLOB - 217.9 KiB] | 3 | 8acced70-17ae-4a65-8466-6b910c674869 |
+----+-----------+----+-----------------------------------------------+

从图片中可以看出,这是错误的,因为 imagedata 中的 ID 不同。

最佳答案

您有 2 行具有相同的值:

2 - [BLOB - 217.9 KiB]; 
3 - [BLOB - 217.9 KiB];

因此,如果 price_history 表中的行包含此类数据:

imagename_dioPlus imagename_inkDepot
2 3

它将输出

[BLOB - 217.9 KiB] [BLOB - 217.9 KiB]

不管它们有不同的id。问题是它们有相同的描述。

关于MySQL Join 结果错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31075737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com