如果从Jobs表包含超过200万条记录的Oracle数据库中的TOAD执行,我有这个SQL查询工具正在快速运行。
select * from Technicians A
left join
(select TechnicianCode,count(*)JobCount from Jobs
where TxnCode in ('Jc','Jcd') group by TechnicianCode) B
on B.TechnicianCode =A.TechnicianCode
无法将其有效转换为linq。
有人可以帮忙吗?
最佳答案
你可以试试这个
var txnDetails = from job in jobs
where job.TxnCode == "Jc" || job.TxnCode == "Jcd"
group job by job.TechnicianCode into g
select new { TechnicianCode = g.Key, count = g.Count() };
然后您可以使用join进行常规选择
from technician in Technicians
join txn in txnDetails on technician.TechnicianCode equals
txn.TechnicianCode into tg
from t in tg.DefaultIfEmpty()
select new {Count = t==null? 0: t.count, ...}
关于c# - 具有联接和计数的快速linq查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44404434/