比如有这样多个表tb1,tb2,tb3,.....,tb20,
我希望查询每个表中的nYear,nMonth,salary
也就是希望以下结果一次查询:
select nYear,nMonth,salary from tb1 where nMonth=12;
select nYear,nMonth,salary from tb2 where nMonth=12;
select nYear,nMonth,salary from tb3 where nMonth=12;
...
select nYear,nMonth,salary from tb20 where nMonth=12;
怎么弄呢?

解决方案 »

  1.   

    select bm,nYear,nMonth,salary from (
    select *,'b1' as bm from tb1
    union all
    select *,'b2' as bm from tb2
    union all
    ...
    select *,'bn' as bm from tbn) a
    where nMonth=12;
      

  2.   

    you have an error in your SQL syntax ... near 'from (
    select *,'b1' as bm from tb1 
    union all
    select *,'b2' as bm from tb'
    at line 1
    是错误提示
      

  3.   

    SELECT bm,nYear,nMonth,salary FROM (
     SELECT *,'b1' AS bm FROM tb1
     UNION ALL
     SELECT *,'b2' AS bm FROM tb2
     ) a
     WHERE nMonth=12;你的代码是什么、