近期有要緊的問題,我要儲存一個素數區間表,並返回其中所有質數。我自己覺得我的資料表有點問題,在商用環境下能優化的地方很多,但我看不出來。請教各位具體方法如何拆分下圖中重複的資料數據?
[]!(https://ithelp.ithome.com.tw/upload/images/20230814/20162136Oeb2rszKkf.png)
json 解出end value 代 底下 程式
https://www.geeksforgeeks.org/stored-procedure-for-prime-numbers-in-mysql/
恩~純玩玩@_@a...
Create table Test(
PP varchar(max)
);
insert into Test
values('{"start":"1","end":"13"}')
,('{"start":"1","end":"7"}')
,('{"start":"1","end":"200"}')
create function Prime(@Start int ,@End int )
returns varchar(max)
begin
declare @i int,@j int,@r int
declare @Str varchar(max)
set @Str = '['
set @i=@Start
while @i<@End
begin
set @j=1
set @r=1
while @j<@i
begin
if @i%@j=0 and @i<>@j and @j<>1
begin
set @r=0
break
end
set @j=@j+1
end
if @r=1
set @Str = @Str + ' ' + Convert(varchar,@i)
set @i=@i+1
end
set @Str = @Str + ' ]'
return @Str
end
select PP
,dbo.Prime(json_value(PP,'$.start'),json_value(PP,'$.end'))
from Test