求各位大神帮我把如下二句sql优化一下,页面查询速度太慢了
<!--搜索次数--><selectid="getUserNumOfSearch"resultType="com.huawei.prettysearch.spi.enti...
<!--搜索次数-->
<select id="getUserNumOfSearch" resultType="com.huawei.prettysearch.spi.entity.UserSearchEntry"
parameterType="Map">
select trunc(logtime ,'dd') AS logTime,
count(*) as search_count
from t_dsdp_sh_keyword_log
group by (userId,trunc(logtime ,'dd'))
having userId = #{userId} AND trunc(logtime,'dd')
between trunc(sysdate-interval '${count}' day ,'dd')
and trunc(sysdate-interval '1' day,'dd') order by trunc(logtime ,'dd')
</select>
如上图,查询速度太慢,怎么优化! 展开
<select id="getUserNumOfSearch" resultType="com.huawei.prettysearch.spi.entity.UserSearchEntry"
parameterType="Map">
select trunc(logtime ,'dd') AS logTime,
count(*) as search_count
from t_dsdp_sh_keyword_log
group by (userId,trunc(logtime ,'dd'))
having userId = #{userId} AND trunc(logtime,'dd')
between trunc(sysdate-interval '${count}' day ,'dd')
and trunc(sysdate-interval '1' day,'dd') order by trunc(logtime ,'dd')
</select>
如上图,查询速度太慢,怎么优化! 展开
1个回答
展开全部
1、HAVING使用方法有误,将这些条件,放到WHERE中
2、GROUP BY中,UserID是否有必要? 可以去掉-- 业务上,一般不这么干
SELECT trunc(logtime ,'dd') AS logTime,
count(*) as search_count
FROM t_dsdp_sh_keyword_log
WHERE userId = #{userId}
AND trunc(logtime,'dd') between trunc(sysdate-interval '${count}' day ,'dd')
AND trunc(sysdate-interval '1' day,'dd')
GROUP BY trunc(logtime ,'dd')
ORDER BY trunc(logtime ,'dd')
追问
感觉很 NB。。
柚鸥ASO
2024-03-16 广告
2024-03-16 广告
ASO优化中的关键词覆盖是指通过选取合适的关键词,使得你的APP在用户搜索这些关键词时能够被展示在靠前的位置,从而获得更多的曝光和下载量。以下是一些关键词覆盖的策略:1. 了解用户需求和行为:了解目标用户群体的需求和行为,选取与APP相关性...
点击进入详情页
本回答由柚鸥ASO提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询