Is it possible to create multi-tiered WHERE statements in mySQL
Posted
by Brendan
on Stack Overflow
See other posts from Stack Overflow
or by Brendan
Published on 2010-04-27T22:16:12Z
Indexed on
2010/04/27
22:43 UTC
Read the original article
Hit count: 199
I'm currently developing a program that will generate reports based upon lead data. My issue is that I'm running 3 queries for something that I would like to only have to run one query for. For instance, I want to gather data for leads generated in the past day
submission_date > (NOW() - INTERVAL 1 DAY)
and I would like to find out how many total leads there were, and how many sold leads there were in that timeframe. (sold=1 / sold=0). The issue comes with the fact that this query is currently being done with 2 queries, one with WHERE
sold= 1
and one with WHERE
sold= 0
. This is all well and good, but when I want to generate this data for the past day,week,month,year,and all time I will have to run 10 queries to obtain this data. I feel like there HAS to be a more efficient way of doing this. I know I can create a mySQL function for this, but I don't see how this could solve the problem.
Thanks!!
© Stack Overflow or respective owner