我正在尝试使用两列的最小值选择LOC_LOC_ID
。
有什么想法吗?
SELECT DISTINCT
LOC_LOC_ID as S,
MIN(LWWKS_TOTAL_SALES_VAL) as V,
MIN(LWWKS_TOTAL_SALES_QTY) as Q
FROM
Apollo.dbo.TBL_FACT_SALES_LWWKS
GROUP BY
LOC_LOC_ID
答案 0 :(得分:1)
将AdminController
查询包装在派生表中。然后使用group by
表达式返回最小值:
case
或者,取决于OP的要求:
select s, case when v < q then v else q end
from
(
SELECT LOC_LOC_ID as S,
MIN(LWWKS_TOTAL_SALES_VAL) as V,
MIN(LWWKS_TOTAL_SALES_QTY) as Q
FROM
Apollo.dbo.TBL_FACT_SALES_LWWKS
GROUP BY LOC_LOC_ID
) dt