下面发错了重新发一下这个问题,怎么能实现
数据库中用5张表
table1:
(c_code,c_name...)
c-1 a
table2:
(c_code,p_code,p_name,p_pinfan..)
c-1 0001 d f
table3:
(zwfh,c_code,p_code,number,time..)zwfh是主健
sds c-1 0001 234 2007-6-5
fdf c-1 0001 323 2007-6-8
eff c-2 0001 33 2007-6-9
table4:
(c_code,p_code,sell_number,sell_time..)
c-1 0001 34534 2007-6-9
我想查询出如下:
c_name,p_name,p_pinfan,sum(table3.number),(table3.time),sell_number,sell_time
------解决方案--------------------
select a.c_name,b.p_name,b.p_pinfan,
c.number,c.time,d.sell_number,d.sell_time
from table1 a inner join table2 b
on a.c_code=b.c_code inner join
(select c_code,p_code,sum(number) as number,max(time) as time
from table3 group by c_code,p_code) c
on b.c_code=c.c_code and b.p_code=c.p_code
inner join table4 d
on b.c_code=d.c_code and b.p_code=d.p_code
(table3.time) 应该取一组中最大的最小的?