id全部为升序的
select a.id, a.moduleid,b.modulename, a.officepath, a.htmlpath, a.title, a.content, a.attachedfile, a.permitflag, a.linkinfo, a.flag, a.isdownloadable, TO_CHAR(a.writedate,'yyyy-mm-dd') as writedate from information a,module b,department c where a.moduleid=b.id and b.deptid=c.id and b.modulename='部门公告栏' and a.isdeleted='0' and b.isdeleted='0' and c.isdeleted='0' group by c.id,a.id, a.moduleid,b.modulename, a.officepath, a.htmlpath, a.title, a.content, a.attachedfile, a.permitflag, a.linkinfo, a.flag, a.isdownloadable, writedate and rownum < 2
我这样写有错,帮我改改
select a.id, a.moduleid,b.modulename, a.officepath, a.htmlpath, a.title, a.content, a.attachedfile, a.permitflag, a.linkinfo, a.flag, a.isdownloadable, TO_CHAR(a.writedate,'yyyy-mm-dd') as writedate from information a,module b,department c where a.moduleid=b.id and b.deptid=c.id and b.modulename='部门公告栏' and a.isdeleted='0' and b.isdeleted='0' and c.isdeleted='0' group by c.id,a.id, a.moduleid,b.modulename, a.officepath, a.htmlpath, a.title, a.content, a.attachedfile, a.permitflag, a.linkinfo, a.flag, a.isdownloadable, writedate and rownum < 2
我这样写有错,帮我改改
a.attachedfile, a.permitflag, a.linkinfo, a.flag, a.isdownloadable,
TO_CHAR(a.writedate,'yyyy-mm-dd') as writedate
FROM information a,module b,department c
WHERE a.moduleid=b.id and
b.deptid=c.id and
b.modulename='部门公告栏' and
a.isdeleted='0' and
b.isdeleted='0' and
c.isdeleted='0'
GROUP BY c.id,a.id, a.moduleid,b.modulename, a.officepath, a.htmlpath, a.title,
a.content, a.attachedfile, a.permitflag,
a.linkinfo,a.flag,a.isdownloadable, writedate
HAVING rownum < 2
你的最后一句,and rownum < 2 不明白
改为上面的
a.id,
a.moduleid,
b.modulename,
a.officepath,
a.htmlpath,
a.title,
a.content,
a.attachedfile,
a.permitflag,
a.linkinfo,
a.flag,
a.isdownloadable,
TO_CHAR(a.writedate,'yyyy-mm-dd') writedate
from
information a,
module b,
department c
where
a.moduleid=b.id
and b.deptid=c.id
and b.modulename='部门公告栏'
and a.isdeleted='0'
and b.isdeleted='0'
and c.isdeleted='0'
and rownum<=2 --把返回行的数量在这里限制,如果你想得到group by 后的
2行,则把 and rownum<=2放在整个select 的后面
group by
c.id,
a.id,
a.moduleid,
b.modulename,
a.officepath,
a.htmlpath,
a.title,
a.content,
a.attachedfile,
a.permitflag,
a.linkinfo,
a.flag,
a.isdownloadable,
TO_CHAR(a.writedate,'yyyy-mm-dd') --这里不要用别名writedate
--and rownum < 2 --把这一行删除