|
(以表3的CODE为条件,表1、表2的对应记录合并在一起)
可以有几种理解:
1、表1、表2的对应记录的code必须在表3中。楼上就是这种情况的处理方法之一
2、表3的所有记录,以及表1、表2的对应记录的code必须在表3中。这种情况还得另外处理,如下:
SELECT a.code, Max(a.intime) AS intime之最大值, Max(a.outtime) AS outtime之最大值, Sum(a.innum) AS innum之总计
FROM [SELECT 表1.code,表1.intime,表1.innum,0 as outtime
FROM 表1
UNION ALL SELECT 表2.code,0 as intime,0 as innum,表2.outtime
FROM 表2 union SELECT 表3.code,0 as intime,0 as innum,0 as outtime
FROM 表3]. AS a
GROUP BY a.code
HAVING (((a.code) In (select code from 表3))) |
|