需要Linq的幫助。Linq Datatable子集使用group by和count> 1
我有一個數據表,它看起來像下面 I just have the W_text with me to search
使用上面的數據表,我想提取具有以下結果行的子集
The key to search is "First Employee"
所以你可以請參閱我想獲取那些W_Text值爲「First」和「Employee」但具有相同l_id的行的子集。
在數據庫術語中,這將是表1中的Select *,其中('First','Employee')組中的W_Text具有l_id> 1(或類似的東西)。
我如何在C#中使用數據表達到這一點?
我試着玩了下面的代碼,但是這也給了我整個datatable其他行。我不確定如何使用group by和having子句。如果有人能在這方面幫助我,我會說。
var results = from myRow in dtResult.AsEnumerable()
where myRow.Field<string>("W_Text") == "First" ||
myRow.Field<string>("W_Text") == "Employee"
select myRow;
dtCopy = results.CopyToDataTable();
感謝Abdhulla。這也給了我一個包含所有「First」和「Employee」事件的數據集。我想只是那個「First」和「Employee」都有相同l_id的數據集,換句話說,其中count(l_id)大於1 – DevNovice
在新編輯之後檢查上面顯示的代碼片段。 –
工作出色! 非常感謝阿卜杜拉。真的很感謝你的迴應。 你能幫我理解代碼的工作原理嗎?我很難理解Linq,尤其是這些集合函數。 再次感謝! – DevNovice