2个表ID 对应吗 ? select a.name,b.time from table1 as a left join table2 as b on a.id=b.id whrer b.time<今天 order by b.time desc
两个表之间有关联的字段吗? 如果是id关联,可以这样写(假设表一名称为table1,表二名称为table2) select table1.name ,table2.time from table1 ,table2 where table1.id=table2.id order by table2.time DESC或者 select table1.name ,table2.time from table1 right outer jion table2 on table1.id=table2.id group by table2.time DESC
不一定,我觉得难点反而是这里。注意lz问题,离今日最近的排序。但lz没说日期不会超过今天的。但估计1条sql做不了这样的排序,lz可以分开两条执行,一条时间小于今日,倒序;一条时间大于今日,顺序。记得要注意效率。至于两表之间的查询,用left join之类的就可以了。没有给出条件,只能说这么多了
select a.name,b.time from table1 as a left join table2 as b on a.id=b.id whrer b.time<今天 order by b.time desc
如果是id关联,可以这样写(假设表一名称为table1,表二名称为table2)
select table1.name ,table2.time from table1 ,table2 where table1.id=table2.id order by table2.time DESC或者
select table1.name ,table2.time from table1 right outer jion table2 on table1.id=table2.id group by table2.time DESC