谁能帮助我解决这个问题
select d.good_price,d.good_id,a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit from(select a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit from In_storage_Detail a,Good_Info b where a.good_id=b.id and a.operate_time between '2012-11-22 00:00:00' and '2012-11-23 00:00:00' and a.hotel_id=1 and b.hotel_id=1 group by a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit) c,out_storage_detail d where c.good_id=d.good_id group by d.good_price,d.good_id
为什么我把这条SQL放在oracl数据库里执行,总是说a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit 得别名不对,这条语句该怎样写,求大大们指点下小弟
但是类似这样就能执行成功
select d.good_price,d.good_id from(select a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit from In_storage_Detail a,Good_Info b where a.good_id=b.id and a.operate_time between '2012-11-22 00:00:00' and '2012-11-23 00:00:00' and a.hotel_id=1 and b.hotel_id=1 group by a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit) c,out_storage_detail d where c.good_id=d.good_id group by d.good_price,d.good_id
令小弟求大侠,教教我如何写聚集函数,每次遇到报表,多表查询去除重复数据时我的心情总是很沉重,因为我不知道怎样用group by,小弟求高手们能分享下如何才能灵活运用聚集函数group by
[最优解释]
楼主为啥就不愿意稍微排个版呢?
select d.good_price,d.good_id,a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit
from (
select a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit
from In_storage_Detail a,Good_Info b
where a.good_id=b.id and a.operate_time between '2012-11-22 00:00:00' and '2012-11-23 00:00:00' and a.hotel_id=1 and b.hotel_id=1
group by a.good_id,a.good_price,a.good_num,b.good_name,b.good_unit
) c, out_storage_detail d
where c.good_id=d.good_id group by d.good_price,d.good_id