[英]Grouping in T-SQL
您能建議從該表中如何在SQL中進行這種特殊分組嗎
id FromDate ToDate UPC price IsGroupSpecial
3 2013-12-27 2013-12-30 6400000087492 315.00 1
2 2013-12-27 2013-12-31 6400000087492 405.00 0
需要選擇所有具有最低價格的商品,但ID不一定是最小值-ID應該從IsGroupSpecial = 0的那一行中獲取
我認為您正在尋找這種類型的查詢。 如果您只查找價格低於group by子句的所有記錄,則沒有必要。
select *
from table
where price = (select min(price) from table))
如果我理解正確
select UPC, min(price), x.id
from table t1
cross apply (select id from table t2 where t2.IsGroupSpecial =0 and t1.UPC=t2.UPC) X
group by UPC, x.id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.