interbase里group by 的使用问题,请大家帮俺看看
metro 2003-10-22 08:45:29 问题1:
在interbase里数据库里我有一个measure_his表,
其中有lzx,measure_his,shongji_date,period等列。
现在我想查出不同lzx列对应shongji_date的最新日期 并且period
>0 并且youxiao_date在2003年8月份的内容
因为lzx列里的数据有的是重复的,所以我用group by 对其分组, 但interbase调试时
要报如下错误:
“SQL error code = -104
invalid column reference
Statement: select max(shongji_date),lzx,mc,youxiao_date
from measure_his group by lzx
having period>0 and youxiao_date<='2003-8-30' and youxiao_date>='2003-8-1' ”
我试着将查询语句改为:select max(shongji_date),lzx,mc,youxiao_date
from measure_his group by lzx,mc,youxiao_date
having period>0 and youxiao_date<='2003-8-30' and youxiao_date>='2003-8-1'
错误没有了,但是查出来的结果不是我想得到的值。(多出几项,没有过滤完,而且多出记录
的max(youxiao_date)列的值不对)
请问group by 后可以跟几个列? 如果要解决问题1,还有其他的查询方法吗?