gpt4 book ai didi

sql - 存储过程重构

转载 作者:行者123 更新时间:2023-12-02 18:34:04 24 4
gpt4 key购买 nike

我正在考虑重构此存储过程,因为它似乎导致使用 100% DTU 容量的 Azure DB 超时。

有人对我如何改进存储过程中使用的 SQL 有任何建议吗?

谢谢

declare @value bigint
declare @secondValue bigint

select @value = count(*) from [dbo].[myTable]
where ([Name] = 'something') AND ([Type] = 'paid') AND profilestatus = 'something'
and ExpiresOn >= CURRENT_TIMESTAMP

select @trialing = count(*) from [dbo].[myTable]
where ([Name] = 'something') AND ([Type] = 'avalue') AND profilestatus = 'something'
and ExpiresOn >= CURRENT_TIMESTAMP

select @value as firstValue, @secondValue as secondValue

客户统计:

enter image description here

最佳答案

我发现您想要获取两个计数 - [Type] 的两个值中的每一个计数,在这种情况下,group by 应该会显着提高您的性能:

select [Type], count(*) AS cnt
from [dbo].[myTable]
where ([Name] = 'something') AND ([Type] IN ('paid', 'avalue')) AND profilestatus = 'something' AND ExpiresOn >= CURRENT_TIMESTAMP
group by [Type]

您可以将该查询合并到您的存储过程中,期望结果集中有两条记录。

关于sql - 存储过程重构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69030783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com