We have a this table and random data load:
CREATE TABLE [dbo].[webscrape](
[id] [int] IDENTITY(1,1) NOT NULL,
[date] [date] NULL,
[value1] [int] NULL,
[value2] [int] NULL,
[value3] [int] NULL,
[value4] [int] NULL,
[value5] [int] NULL,
[sumnumbers] AS ([value1]+[value2]+[value3]+[value4]+[value5])
) ON [PRIMARY]
declare @date date = '1990-01-01',
@endDate date = Getdate()
while @date<=@enddate
begin
insert into [dbo].[webscrape](date,value1,value2,value3,value4,value5)
SELECT @date date,FLOOR(RAND()*(36-1)+1) value1,
FLOOR(RAND()*(36-1)+1) value2,
FLOOR(RAND()*(36-1)+1) value3,
FLOOR(RAND()*(36-1)+1) value4,
FLOOR(RAND()*(36-1)+1) value5
set @date = DATEADD(day,1,@date)
end
select * from [dbo].[webscrape]
In SQL how can we return pair of values that have gone the longest without occurring on a given date?
And (if you happen to know) in Power BI Q&A NLP, how do we map so that so we can ask in natural language "when have the most overdue pairs occurred?"
Overdue being the pair of numbers with the longest stretch of time since occurring as of the given date.
UPDATE: I am trying this very ugly code. Any ideas:
select *
from (
select date,value1 number1,value2 number2 from webscrape union all
select date,value1,value3 from webscrape union all
select date,value1,value4 from webscrape union all
select date,value1,value5 from webscrape union all
select date,value2,value3 from webscrape union all
select date,value2,value4 from webscrape union all
select date,value2,value5 from webscrape union all
select date,value3,value4 from webscrape union all
select date,value3,value5 from webscrape union all
select date,value4,value5 from webscrape
) t order by date
----------------------------------
select t.number1,t.number2, count(*)
as counter
from (
select value1 number1,value2 number2 from webscrape union all
select value1,value3 from webscrape union all
select value1,value4 from webscrape union all
select value1,value5 from webscrape union all
select value2,value3 from webscrape union all
select value2,value4 from webscrape union all
select value2,value5 from webscrape union all
select value3,value4 from webscrape union all
select value3,value5 from webscrape union all
select value4,value5 from webscrape
) t
group by t.number1,number2
order by counter
Thanks for any help.