请教一个sql如何变成sql
下面有两个表,和sql语句没法搞成linq了。有人帮忙么,多谢了!!
Table1 Table2
C1 C2 C3 C4
1 Emergency 1 00:00.0
2 Alert 7 00:00.0
3 Critical
4 Error
5 Warning
6 Notice
7 Notice
8 Informational
9 Informational
10 Debug
select COUNT(table2.c3) a, table1.c2
from table1
left join EventDt on table1.c1=table2.c3
group by table1.c2
结果集如下:
a c2
0 Alert
0 Critical
0 Debug
1 Emergency
0 Error
0 Informational
1 Notice
0 Warning
--------------------编程问答-------------------- var q = from p in db.Table1 group p by p.c2 into g select new { g.Key,g.Count() }; --------------------编程问答-------------------- 一共有两张表Table1和table2.
发贴给我换样子了。两个表进行group by。sql到linq写不好了,这个好写么?
Table1
C1 C2
1 Emergency
2 Alert
3 Critical
4 Error
5 Warning
6 Notice
7 Notice
8 Informational
9 Informational
10 Debug
Table2
C3 C4
1 datas
7 datas
结果集如下:
c5 c6
0 Alert
0 Critical
0 Debug
1 Emergency
0 Error
0 Informational
1 Notice
0 Warning
--------------------编程问答-------------------- select COUNT(table2.c3) a, table1.c2
from table1
left join EventDt on table1.c1=table2.c3
group by table1.c2
=======
var q=from t1 in db.table1
join t2 in db.table2
on t1.c1 equals t2.c3
group t1 by t1.c2 into t3
select new{t1.c2,a=t3.Count(t=>t3.c3)}; --------------------编程问答-------------------- 是否可以让结果集为8行,所有的状态都存在?这个linq在结果集中是0的就不存在。
查到一些资料是要加DefaultIfEmpty()。没哟写明白。Tim能指教一下么? --------------------编程问答-------------------- --------------------编程问答-------------------- q107770540
( Tim )
Table1和table2中的列C1和C3是同样的名字。linq中最后select部分有错误
select new{t1.c2,a=t3.Count(t=>t3.c3)};
提示
t=>t3.c3不能将int转化为bool --------------------编程问答-------------------- 有人知道么,帮个忙啊,好闹心
补充:.NET技术 , LINQ