我有一個表Plan
與下面的示例數據
我想要聚合通過PlanMonth和PlanStatus我想要的結果,如果任何的(在一個組)值是Drafted
我得到起草的結果,否則Under Approval
。我曾嘗試使用下面的查詢動態列值由(SQL Server和LINQ)
select PlanMonth, case when Flag=1 then 'Drafted' else 'Under Approval' end as PlanStatus
from
(select p.PlanMonth, Max(CASE WHEN p.PlanStatus = 'Drafted' THEN 1 ELSE 0 END) Flag
from Plans p
group by p.PlanMonth
) inquery
我已經諮詢this blog post做到了。它有什麼問題嗎?此外,如果有人能幫助我把它翻譯到LINQ我會很感激
@Mikiael我需要一個像'Drafted'文字表述和'approval' UR查詢下會給我1或0 –
@MuhammadAdeelZahid若您的樣本數據是你說是的。 –