SQL语句优化

chinabdx chinabdx 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

declare @deptcode varchar(4),
@startdate datetime,
@enddate datetime
set @deptcode = '0201'
set @startdate = '2016-07-01 00:00'
set @enddate = '2016-07-22 23:59'

SELECT c.stddeptcode,
c.stddeptname,
sum(a.actualmoney) as '销售额',
count(distinct a.flowno) as '客流量',
convert(decimal(18,2),round(sum(a.actualmoney)/count(distinct a.flowno),2)) as '客单价'
FROM inf_gdscode b
left join acc_goodsflow a on b.gdscode = left(a.gdssalecode,8)
and a.deptcode = @deptcode
and a.saletime >= @startdate
AND a.saletime <= @enddate
left join inf_stddept c on b.stddept = c.stddeptcode
where c.stddeptcode in (21,22,23)
group by c.stddeptcode,
c.stddeptname


这个语句还有没有优化的空间了
c.stddeptcode in (21,22,23)这句能不能用Exists进行过滤
...全文
评论 6
收藏 已收藏
分享
返回顶部
chinabdx
MS-SQL Server 34,877 成员 254,635 内容