日期:2014-05-16 浏览次数:20817 次
SELECT a.co ,a.c4 ,b.c ,b.c9 ,c.c9 ,b.c4/b.c9*10000 ,c.c4/c.c9*10000 FROM table_1 a RIGHT JOIN (SELECT co,MAX(c1) AS c1,c4,c9 FROM table_2 GROUP BY co )b ON a.co=b.co LEFT JOIN table_2 c ON b.co=c.co AND b.c1>c.c1 AND NOT EXISTS(SELECT 1 FROM table_2 WHERE co=b.co AND c1<b.c1 AND c1>c.c1) WHERE YEAR(b.c1)=YEAR(20120331000000) AND QUARTER(b.c1)=QUARTER(20120331000000)