ysbin(提问者)select tb.md,tb.mdmc,ta.rq,ta.xingqi,ta.tianqi,ta.liuru,tb.xsbs,tb.xszje from
(SELECT md,rq
,xingqi
,tianqi
,liuru
,liuchu
from keliu
where rq>=\'${开始日期}\'
and rq<=\'${结束日期}\'
)ta
join
(select md,mdmc,rq,sum(xszje) xszje,sum(xsbs)xsbs from sale_daily
where mdmc=\'${门店}\'
and 1=1 ${if( len(fine_username)== 0 , \"\", \"and md in (select md from jhyb_user where name = \'\"+fine_username+\"\' ) \" )}
group by md,mdmc,rq) tb on ta.md=tb.md and ta.rq=tb.rq
order by rq
Z4u3z1 回复 ysbin(提问者)select tb.md,tb.mdmc,ta.rq,ta.xingqi,ta.tianqi,ta.liuru,tb.xsbs,tb.xszje from
(SELECT md,rq ,xingqi ,tianqi ,liuru ,liuchu from keliu where rq>=\'${开始日期}\' and rq<=\'${结束日期}\' ) ta
inner join (select md,mdmc,rq,sum(xszje) xszje,sum(xsbs)xsbs from sale_daily where mdmc=\'${门店}\' and 1=1 ${if( len(fine_username)== 0 , \"\", \"and exists (select md from jhyb_user where sale_daily.md=jhyb_user.md name = \'\"+fine_username+\"\' ) \" )} group by md,mdmc,rq) tb
on ta.md=tb.md and ta.rq=tb.rq order by rq ------试试这个 join指定连接方式为inner;把in 改成exists;最后把on用到的字段统一字符类型(比如都为字符类型)
ysbin(提问者)select tb.md,tb.mdmc,ta.rq,ta.xingqi,ta.tianqi,ta.liuru,tb.xsbs,tb.xszje from
(SELECT md,rq
,xingqi
,tianqi
,liuru
,liuchu
from keliu
where rq>=\'${开始日期}\'
and rq<=\'${结束日期}\'
)ta
join
(select md,mdmc,rq,sum(xszje) xszje,sum(xsbs)xsbs from sale_daily
where mdmc=\'${门店}\'
and 1=1 ${if( len(fine_username)== 0 , \"\", \"and md in (select md from jhyb_user where name = \'\"+fine_username+\"\' ) \" )}
group by md,mdmc,rq) tb on ta.md=tb.md and ta.rq=tb.rq
order by rq
我在SQL里面直接执行,秒出结果的,语句也不复杂,就一年的数据300多行