在 MS SQL 中,有没有一种方法可以根据第一列的值将条件列添加到如下的联合查询中?
基本上我试图将 bin 值添加为第四列,如果部件值类似于 ('%XX') 或让它显示 0,到目前为止,我只能添加另一列反映 MAX(part_bins.bin)如果代码不符合,列。
SELECT part_bins.part AS part,
SUM(part_bins.free_stock) AS FREE_STOCK,
MAX(PART_BINS.BIN) AS Bin
FROM part_bins
LEFT OUTER JOIN part ON part_bins.part = part.part
WHERE (part_bins.free_stock > 0)
GROUP BY part_bins.part
UNION
SELECT part.master_part AS part,
SUM(part_bins.free_stock) AS FREE_STOCK,
MAX(PART_BINS.BIN) AS Bin
FROM part_bins
LEFT OUTER JOIN part ON part_bins.part = part.part
WHERE (part_bins.free_stock > 0)
GROUP BY part.master_part