SQLserver: declare @mdmc nvarchar(50) ='江北店' select ta.mdmc,ta.louceng,ta.spid,ta.spmc from (select md,mdmc,louceng,spid,spmc from zg_sysinfo where mdmc=@mdmc ) ta left join (select mdmc,loudong,louceng,quyu,spid,spmc,sum(xsze)xsze from view_xshb where rq>='2023-01-25' and rq<='2023-02-08' group by mdmc,loudong,louceng,quyu,spid,spmc ) tb on ta.mdmc=tb.mdmc and ta.louceng=tb.louceng and ta.spid=tb.spid where tb.xsze is null --说明:zg_sysinfo 700条记录,视图view_xshb 20万条记录。 --declare 定义一个参数mdmc,把这个值“江北店”赋给他 where mdmc=@mdmc 秒出结果。 但是为什么我用where mdmc='江北店' 这样执行要50秒。 这有什么区别,不能这么写吗? |