建立10个下面结构的表 (tb1...tb10)
create table tb1
(
intime datetime,
tid varchar(10)
);每个表插入数据;
insert tb1 values('2011-4-1 12:00:00','1');
insert tb1 values('2011-4-2 12:00:00','1');
insert tb1 values('2011-4-3 12:00:00','1');
insert tb1 values('2011-4-4 12:00:00','1');
insert tb1 values('2011-4-5 12:00:00','1');想得出结果:
tb1.intime tb2.intime [...] tb10.intime  
================================================
'2011-4-5 12:00:00' '2011-4-5 12:00:00' [...] '2011-4-5 12:00:00'

解决方案 »

  1.   

    select intime as t1.intime,
    (select intime from tid1 where intime='2011-4-5 12:00:00) as  t2.intime,
    ...
     from tid1 where intime='2011-4-5 12:00:00'
      

  2.   

    select group_concat(intime) from tb1
      

  3.   

    intime 是值是未知的。
    有10个表啊。。
      

  4.   

    select A.intime,B.intime....
    from tb1 A,tb2 B...
    where a.intime=b.intime and b.intime=c.intime...
      

  5.   

    select max(intime) as t1.intime,
    (select max(intime) from tid1) as t2.intime,
    ...
     from tid1 
      

  6.   


    为什么只输出2011-4-5 12:00:00的?其它日期的不需要,根本什么原则? (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  7.   


    简单说,就是把TB1到TB10 10个表中相同tid的最新记录数据的时间(intime),
    组合起来显示出来,结果应该只有一条。其实rucypli的写法,和我现在写的差不多,只不过我加了LIMIT 1;
    而且这样的写法没有判断相同的tid,这个不过是我查询记录时,临时想到的需求。
    其他繁琐的写法我也想过了,就是查询这10个表,然后比较下每个表的最新intime就行了。
      

  8.   

    select tid,max(intime) from (
    select tid,intime from tb1
    union all
    select tid,intime from tb1
    ...
    union all
    select tid,intime from tb10) a group by tid对结果再转置
      

  9.   


    下面这条SQL语句已经完全符合你提供的例子的要求了。select 
    (select max(intime) from tb1 where id=1) as tb1_intime,
    (select max(intime) from tb2 where id=1) as tb2_intime,
    (select max(intime) from tb3 where id=1) as tb3_intime,
    (select max(intime) from tb4 where id=1) as tb4_intime,
    (select max(intime) from tb5 where id=1) as tb5_intime,
    (select max(intime) from tb6 where id=1) as tb6_intime,
    (select max(intime) from tb7 where id=1) as tb7_intime,
    (select max(intime) from tb8 where id=1) as tb8_intime,
    (select max(intime) from tb9 where id=1) as tb9_intime,
    (select max(intime) from tb10 where id=1) as tb10_intime;
      

  10.   

    wwwwb 的执行结果是,每个tid在这些表中的最新indate时间,和我的需求差很远。ACMAIN_CHM的语句基本差不多,只是我想id也是个动态的,因为表中的id也不只有1,貌似这需求还挺复杂的,分太少了,不好意思再问了。
     
      

  11.   

    wwwwb 的执行结果是,每个tid在这些表中的最新indate时间,和我的需求差很远。
    你的要求:10个表中相同tid的最新记录数据的时间(intime),select tid,max(intime) from (
    select tid,intime from tb1
    union all
    select tid,intime from tb1
    ...
    union all
    select tid,intime from tb10) a group by tid
      

  12.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。