select * from table1
union
select * from table2
union
select * from table3

解决方案 »

  1.   

    用union啊
    select distinct d.* from  (select * from  a 
    union 
    select * from  b 
    union 
    select * from  c 
    )  d
      

  2.   

    --纵向显示?"select * from 表1
    union 
    select * from 表2
    union
    select * from 表2
      

  3.   

    不用unoin怎么实现了,我主要是用到是Full join
      

  4.   

    首先你要说明,是将三个表横向显示,还是纵向显示.如果是纵向显示,就是用union
    如果是横向显示,才是用full join
      

  5.   

    select distinct * from 
    (select * from table1
    union
    select * from table2
    union
    select * from table3)f
      

  6.   

    CREATE TABLE dbo.MobileUserstatus+str1+(  
                       CustomerID    char (18) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
                         UserstatusName char (26) COLLATE Chinese_PRC_CI_AS NULL , 
                          Balance  float default 0.00, 
                          Arrearage  float  default 0.00 , 
                         setsrvName Char(10) '
                         )
    说明:
      1)str1是一个变量;
      表MobileUserstatus1
    131        申请停                     0.0 0.0 5100      
    136        正常                       59.0 7.0 5100      
    132        申请停                     0.0 0.0 5100      
    MobileUserstatus2
    131        申请停                     0.0 0.0 5100      
    135        正常                       59.0 7.0 5100      
    132        申请停                     0.0 0.0 5100      
    MobileUserstatus3
    138        申请停                     0.0 0.0 5100      
    136        正常                       59.0 7.0 5100      
    132        申请停                     0.0 0.0 5100      
    得到的结果
    131        申请停                     0.0 0.0 5100      
    136        正常                       59.0 7.0 5100      
    132        申请停                     0.0 0.0 5100      
    135        正常                       59.0 7.0 5100      
    138        申请停                     0.0 0.0 5100      
      

  7.   

    zjcxc(邹建),还在吗,以上最好用full join 来实现
      

  8.   

    --那这个没错啦,不知道你的str1又想代表什么?
    select * from MobileUserstatus1
    union
    select * from MobileUserstatus2
    union
    select * from MobileUserstatus3
      

  9.   

    --为什么一定要用full join呢?select CustomerID=isnull(a.CustomerID,isnull(b.CustomerID,c.CustomerID))
    ,UserstatusName=isnull(a.UserstatusName,isnull(b.UserstatusName,c.UserstatusName))
    ,Balance=isnull(a.Balance,isnull(b.Balance,c.Balance))
    ,Arrearage=isnull(a.Arrearage,isnull(b.Arrearage,c.Arrearage))
    ,setsrvName=isnull(a.setsrvName,isnull(b.setsrvName,c.setsrvName))
    from MobileUserstatus1 a 
    full join MobileUserstatus2 b on a.CustomerID=b.CustomerID
    full join MobileUserstatus3 c on a.CustomerID=c.CustomerID
      

  10.   

    --要求 CustomerID是主键,不然重复记录多多,去重复加上:select distinct CustomerID=isnull(a.CustomerID,isnull(b.CustomerID,c.CustomerID))
    ,UserstatusName=isnull(a.UserstatusName,isnull(b.UserstatusName,c.UserstatusName))
    ,Balance=isnull(a.Balance,isnull(b.Balance,c.Balance))
    ,Arrearage=isnull(a.Arrearage,isnull(b.Arrearage,c.Arrearage))
    ,setsrvName=isnull(a.setsrvName,isnull(b.setsrvName,c.setsrvName))
    from MobileUserstatus1 a 
    full join MobileUserstatus2 b on a.CustomerID=b.CustomerID
    full join MobileUserstatus3 c on a.CustomerID=c.CustomerID
      

  11.   

    就是代表1,2,3这些数字了但是我还要对这些数据进行比较了刚刚我发错了我要得到的结果,得到的结果就相当于下面的形式
    customerID  setsrvName  Balance   arearage status1 status2  status3
    131            5100        0.0        0.0    申请停  申请停      
    136             5100       59.0   7.0 申请停  正常  正常 
      

  12.   

    --加上就行了嘛select distinct CustomerID=isnull(a.CustomerID,isnull(b.CustomerID,c.CustomerID))
    ,UserstatusName=isnull(a.UserstatusName,isnull(b.UserstatusName,c.UserstatusName))
    ,Balance=isnull(a.Balance,isnull(b.Balance,c.Balance))
    ,Arrearage=isnull(a.Arrearage,isnull(b.Arrearage,c.Arrearage))
    ,setsrvName=isnull(a.setsrvName,isnull(b.setsrvName,c.setsrvName))
    ,status1=isnull(a.setsrvName,'')
    ,status2=isnull(b.setsrvName,'')
    ,status3=isnull(c.setsrvName,'')
    from MobileUserstatus1 a 
    full join MobileUserstatus2 b on a.CustomerID=b.CustomerID
    full join MobileUserstatus3 c on a.CustomerID=c.CustomerID