SQL在联接中返回单行

有人知道如何在下面的示例中将结果限制为一行吗?我得到两行,因为STOCK值有两个不同的结果。不知道如何添加MAX或类似的东西,所以联接的结果只会让我一行...

SELECT * FROM abtItemTbl abt
LEFT JOIN BT_PUBLISHED_WCID_LEVEL bt 
    ON abt.UDA_WCID = bt.PRODUCT_ID
    AND bt.DISPLAY_NAME IS NOT NULL
    AND bt.COUNT_OF_WCID_IMAGES IS NOT NULL
WHERE abt.ITEM_PARENT IS NULL
AND abt.UDA_WCID = '49x1794x116430'

enter image description here

评论
  • shf939899
    shf939899 回复

    您可能需要在加入之前进行汇总:

    LEFT JOIN
    (SELECT bt.PRODUCT_ID, SUM(STOCK) as STOCK
     FROM BT_PUBLISHED_WCID_LEVEL bt 
     WHERE bt.DISPLAY_NAME IS NOT NULL AND
           bt.COUNT_OF_WCID_IMAGES IS NOT NULL
     GROUP BY bt.PRODUCT_ID
    ) bt
    ON abt.UDA_WCID = bt.PRODUCT_ID