A little background: I work for a small not-for-profit organization. We have a PostgreSQL server containing all of our client information dating back to 2001. I've been asked to do some data mining. The problem is that I'm getting weird results.
Note: "tbclients" is the table containing basic information on all clients. "tbvisits" is a table recording when a client comes in. The "clientid" field in the "tbvisits" table is linked to the "id" field in the "tbclients" table.
Here are some queries I've run, and the results the system has given me:
Number returned: 1840
Number returned: 425
Number returned: 0
Now shouldn't the third number be at least 1415? Or am I totally missing something here?
Note: "tbclients" is the table containing basic information on all clients. "tbvisits" is a table recording when a client comes in. The "clientid" field in the "tbvisits" table is linked to the "id" field in the "tbclients" table.
Here are some queries I've run, and the results the system has given me:
Code:
select count(*) from tbclients
where id in (select distinct clientid from tbvisits
where date > '2004-05-29'
and date <= '2005-05-29');
Number returned: 1840
Code:
select count(*) from tbclients
where id in (select distinct clientid from tbvisits
where date > '2005-05-29'
and date <= '2005-06-29');
Number returned: 425
Code:
select count(*) from tbclients
where id in (select distinct clientid from tbvisits
where date > '2004-05-29'
and date <= '2005-05-29')
and id not in (select distinct clientid from tbvisits
where date > '2005-05-29'
and date <= '2005-06-29');
Number returned: 0
Now shouldn't the third number be at least 1415? Or am I totally missing something here?