I have a list of users with corresponding date of birth. Is there any possibility I can get a percentage of users born between 1990 and 2000 in a single SQL query?
The query I tried is as follows:
Select (Select count(distinct user) as users from Visitors
where birthyear between 1990 and 2000)/count(distinct user) from Visitors
But it gives me a zero as result.
CREATE TABLE Visitors ...
statement and a sample of few rows. Are you sure you have bothuser
andusers
as columns in this table? – ypercubeᵀᴹ Oct 14 '18 at 11:43Visitors
table? if the answer is 'yes', what do you expect to happen if the user has 2 different values forbirthyear
... one in the desired range and one outside of the desired range? – markp-fuso Oct 14 '18 at 22:59Visitors.birthyear
? have you verified there are users withbirthyear between 1990 and 2000
, ie, what does the following return:Select count(distinct user) from Visitors where birthyear between 1990 and 2000
? – markp-fuso Oct 15 '18 at 15:28