select a.title,a.intime,b.typename,c.postiltime from document a,type b,postil c where a.typeid=b.typeid and a.documentid=c.documentid and a.pinst_id = 2 这条SQL是正确的可是select a.title,a.intime,b.typename,MAX(c.postiltime) from document a,type b,postil c where a.typeid=b.typeid and a.documentid=c.documentid and a.pinst_id = 2 为什么就报错呢如果MAX不能用,那我怎么做才能取到c.postiltime的最上面一条记录呢(注:ORACLE 库,c.postiltime字段是VARCHAR2,里面放的是表示时间的字符串 )
要一条的话
select top 1 a.title,a.intime,b.typename,c.postiltime from document a,type b,postil c where a.typeid=b.typeid and a.documentid=c.documentid and a.pinst_id = 2 order by c.postiltime desc
group by a.title,a.intime,b.typename
Sql server中:
select max(convert(char,c.postiltime,11)) from....
from document a,type b,postil c
where a.typeid=b.typeid and a.documentid=c.documentid and a.pinst_id = 2 group by a.title,a.intime,b.typename
俺替楼主感谢你.
left join type b on a.typeid=b.typeid
left join postil c on a.documentid=c.documentid
where a.pinst_id = 2
group by a.title,a.intime,b.typename
要一条的话
select top 1 a.title,a.intime,b.typename,c.postiltime from document a,type b,postil c where a.typeid=b.typeid and a.documentid=c.documentid and a.pinst_id = 2 order by c.postiltime desc说得对