项目需要,用linq转换一下的SQL高手进!!在线等
用linq转换下面的sql语句,项目需要select a,sum(b) b,sum(c) c from
(
select BEGIN_TIME a, SUM(call_count)-SUM(ANSWER_COUNT) b,0 as c from [call].[dbo].[STAT_CALL_TOTAL] where BEGIN_TIME between '2010-02-09 00:00:00' and '2010-02-09 23:59:59' and (CALL_TYPE=1 or CALL_TYPE=4) and RESOURCE_ID like '20'+'%'
group by BEGIN_TIME
union
SELECT BEGIN_TIME as a,SUM(CALL_COUNT)-SUM(SUCCESS_COUNT) b,SUM(CALL_COUNT) as c
FROM [call].[dbo].[STAT_QUEUE_TOTAL] where BEGIN_TIME between '2010-02-09 00:00:00' and '2010-02-09 23:59:59' and ROUTE_NAME <>'4401' and ROUTE_NAME='4411'
group by BEGIN_TIME
) t group by t.a --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 你这语句是对的吗? --------------------编程问答-------------------- 这个sql语句。我已经测试了是OK的 --------------------编程问答-------------------- 现在我已经把那两部分用linq写出来了,但是现在unoin不晓得怎么连接起来。
下面是分开的两部分,那个大哥知道连接指导下。
var rds1 = from r1 in db.STAT_CALL_TOTALs
where r1.BEGIN_TIME >= begin.Date && r1.BEGIN_TIME < end.AddDays(1).Date && (r1.CALL_TYPE == 1 || r1.CALL_TYPE == 3) && r1.RESOURCE_ID.StartsWith("20")
group r1 by new
{
r1.BEGIN_TIME
} into g
select new
{
a = (DateTime?)g.Key.BEGIN_TIME,
b = (System.Int32?)(g.Sum(p => p.CALL_COUNT) - g.Sum(p => p.ANSWER_COUNT)),
c=0
};
var rds2 = from r2 in db.STAT_QUEUE_TOTALs
where r2.BEGIN_TIME >= begin.Date && r2.BEGIN_TIME < end.AddDays(1).Date && r2.ROUTE_NAME != "4401" && r2.ROUTE_NAME == "4411"
group r2 by new
{
r2.BEGIN_TIME
} into g1
select new
{
a = (DateTime?)g1.Key.BEGIN_TIME,
b = (System.Int32?)(g1.Sum(p => p.CALL_COUNT) - g1.Sum(p => p.SUCCESS_COUNT)),
c = (System.Int32?)g1.Sum(p => p.CALL_COUNT)
};
--------------------编程问答--------------------
--------------------编程问答-------------------- --------------------编程问答-------------------- 学习了
var total = rsd1.Union(rds2);
补充:.NET技术 , LINQ