日期:2014-05-18  浏览次数:20384 次

多表查询 ,算其中几个字段的总和
SQL code
SELECT a.Id, a.Name, b.C1, b.C2
FROM NoverlName AS a INNER JOIN
      Click AS b ON a.Id = b.Nid AND b.Year = 2012 AND b.Mon = 3



有没有办法把b.c1 b.c2的总和算出来 c1 c2全是int字段

------解决方案--------------------
SQL code


SELECT a.Id, a.Name, b.C1, b.C2,sum(b.C1+b.c2) as total
FROM NoverlName AS a INNER JOIN
 Click AS b ON a.Id = b.Nid AND b.Year = 2012 AND b.Mon = 3
group by a.Id, a.Name, b.C1, b.C2