CREATE table #yourtable ([user_id] int, [comment] varchar...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness

Q&A for physical fitness professionals, athletes, trainers, and those providing health-related needs

CREATE table #yourtable
    ([user_id] int, [comment] varchar(17), [ds] varchar(10))
;
CREATE table #yourtable1
    ([user_id] int, [country] varchar(6))
;
    
INSERT INTO #yourtable
    ([user_id], [comment], [ds])
VALUES
( 121, 'dasdada', '08-01-2020'), 
( 123, 'adasdsada','08-11-2020'),
( 345, 'dsadsada','06-01-2020'),
( 124, 'adasdasdasdsada','08-13-2020'),
( 654, 'dsa213dsada','07-01-2020'),
( 345, 'adadsadasdsada','08-21-2020'),
( 876, 'dsadsadsada','08-16-2020');

INSERT INTO #yourtable1
    ([user_id], [country])
VALUES
(121, 'US'),
(123, 'UK'),
(345, 'CZ'),
(124, 'CZ'),
(654, 'UK'),
(876, 'US');

select  count(c.user_id)/ count(t.user_id) *100  as pct_us_users
from #yourtable t
left join (
    select user_id, country
    from #yourtable1 
    where country = 'US'  -- 2 us users
    ) c
on c.user_id = t.user_id
where ds between '08-01-2020' and '08-31-2020'

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results