查询Tb1到TB12的表中当TID相等时 最新的 插入数据时间(intime)。
大概的表达如下,
select
a.intime  AA
,b.intime      BB
,c.intime      CC
,d.intime      DD
,e.intime      EE
,f.intime      FF
,G.intime      GG
,h.intime      HH
,i.intime  II
,j.intime  JJ
,k.intime  KK
,l.intime  LL
#,m.singindatetime road
from TB1 a,TB2 b,TB3 c,TB4 d,TB5 e,TB6 f,
TB7 g,TB8 h,TB9 i,TB10 j,
TB11 k,TB12 l
where
a.TID=b.TID=c.TID=d.TID=e.TID=f.TID=g.TID
=h.TID=i.TID=j.TID=k.TID=l.TID
order by singindatetime limit 1;
当时上面“order by singindatetime limit 1;”处的语法是错误的,
求正确写法~

解决方案 »

  1.   

    a.TID=b.TID and b.TID=c.TID and ..改成这样,MYSQL中不支持你那种连等a.TID=b.TID=c.TID=d.TID
      

  2.   

    去掉 order by singindatetime。
    我那样的写法也能执行成功。关键在 order by singindatetime 的写法。
      

  3.   

    不好意思,我写错了,
    order by singindatetime 是order by intime因此,关键在 order by intime的写法我刚按ACMAIN_CHM的写法运行了次,
    提示:
    “SQL ERROR(1052):column 'intime' in order clause is ambiguous ”
      

  4.   

    'intime'  这个字段在多个表中都有,你必须说明一下 比如  a.'intime' 。
      

  5.   

    简单说,我想查询这多表最新记录的时间,即:intime,把结果组合起来显示而已。
      

  6.   

    select max(intime) from a union all
    select max(intime) from b union all
    select max(intime) from c union all
    select max(intime) from d 
    .......这样看看
      

  7.   

    这是把结果输出到一列中吧,像结果集一样,如果不加入a.TID=b.TID and b.TID=c.TID and ..这一的限制的话,就可以了,
    加上上句,就不行了:“Unknow column 'a.TID' in 'where clause'”;
      

  8.   

    你的表结构是什么,SQL语句是什么,TB1中有无ID字段 ,检查一下 字段名
      

  9.   

    可以这样理解,所有表只有TID和INTIME 2个字段,
    取所有表TID相等时,最近一条记录的INTIME 值,组合显示出来。
      

  10.   

    贴建表及插入记录的SQL,及要求结果出来看看
      

  11.   

    所有表结构相同:
    TID INTIME
    ============
    1   2011-04-07 10:00:01
    2   2011-04-07 10:00:01
    ....数据随机插入。
      

  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)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  13.   

    建立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'