好的人。我只是新的寫這些查詢,所以去我的容易... 我想找到2個字段之間的最小日期,我已經找出瞭如何爲SUM做但不是MIN(顯然+不適用於分鐘...) 正如你將從下面看到的,第一行(**中的行)是不正確的(我知道不應該有一個,但我已經放棄了)。下一行是完美的,正是我想要實現與MIN代碼... 基本上我有2個表(ScanLine和庫存)我試圖從這兩個表中獲取Min ProductionDate,在相同的行...SQL Server 2014 - 如何找到兩個表之間的最短日期
**我不想使用別名的加入,我想盡可能避免使用UNION **
SELECT (SELECT min(inventory.productiondate)),
(SELECT min(scanline.productiondate)) AS OldDate,
(SELECT sum(Inventory.NetWeight)) + (SELECT sum(scanline.weight)) AS Wgt,
sum(inventory.units) AS Qty,
count(inventory.palletbarcode) AS Pallets
FROM scowms.inventory
LEFT OUTER JOIN
scowms.scanline
ON scowms.inventory.barcode = scowms.scanline.barcode
WHERE inventory.locationbarcode = '2D03D';
請編輯您的問題,並提供樣本數據和預期結果。 –
如果您只是希望兩個表中的獨立最小值不需要加入。 –