0
SQL:LINQ - 3子由與組選擇計數
SELECT i.name, l.city, COUNT(l.city) AS num
FROM locality l
JOIN event e ON e.ID_locality = l.ID
JOIN program p ON p.ID_event = e.ID
JOIN interpreter i ON i.ID = p.ID_interpreter
WHERE i.name = 'XXXX'
GROUP BY l.city
HAVING COUNT(l.city) = (
SELECT MAX(num)
FROM (SELECT COUNT(city) AS num
FROM (SELECT l.city FROM locality l
JOIN event e ON e.ID_locality = l.ID
JOIN program p ON p.ID_event = e.id
JOIN interpreter i ON i.ID = p.ID_interpreter
WHERE i.name = 'XXXX'
GROUP BY l.city) tmp) tmp2)
LINQ:
var q4 = from l in db.locality
join e in db.event on l.ID equals e.ID_locality
join p in db.program on e.ID equals p.ID_event
join i in db.interpreter on p.ID_interpreter equals i.ID
where i.name == "XXXX"
group l by l.city into grp
你好,我 RLY有嚴重的問題,這種選擇在LINQ。我在SQL中編寫了這個選擇,但我真的不知道如何通過計數來使用多個子選擇...我想選擇解釋器「XXXX」最經常演示的城市以及解釋器在那裏演示的次數。我也檢查了enter link description here,但當我嘗試使用它時,它並沒有幫助我。如果有人能幫助我,我會很開心。 爲了更好的方向:
感謝ü。 Ur解決方案幫助我很多隻是g.count(x => x.city)=(...不工作。我想應該有g.count(x => x.city)==(...但也再選擇需要返回整型數字。曲子g.Count()==這裏需要使用int數。所以還是需要一點修復。 但是謝謝了很多:) – Matwosk 2013-05-05 20:52:45
嗯,是的。g.Count(X => x.city )==必須是。不被注意到的。g.Count(x => x.city)==取消比方括號可能工作的時間晚,我很高興它的工作。 – 2013-05-05 21:04:52