List:General Discussion« Previous MessageNext Message »
From:Jerry van Leeuwen Date:August 15 2002 2:12am
Subject:Re: Combining queries
View as plain text  
On Thu, 15 Aug 2002 10:37, you wrote:
> Is there a way to combine these queries?
>
> SELECT count(SeekID) FROM Seekers
> WHERE DateLastLog<NOW() AND DateLastLog>(NOW()-INTERVAL 7 DAY)
>
> SELECT count(SeekID) FROM Seekers
> WHERE DateLastLog<NOW() AND DateLastLog>(NOW()-INTERVAL 1 MONTH)

SELECT
  SUM(DateLastLog > (NOW()-INTERVAL 7 DAY)) AS Count7Days,
  SUM(DateLastLog > (NOW()-INTERVAL 1 MONTH)) AS Count1Month
FROM
  Seekers
WHERE
  DateLastLog < NOW()
;

> Or these?
>
> SELECT count(ResumeID) FROM Resumes WHERE testResume='1'
> SELECT count(ResumeID) FROM Resumes WHERE HighRank='1'

SELECT
  SUM(testResume='1'),
  SUM(HighRank='1')
FROM
  Resume
;


Basically in both cases you make (very ugly!) use of the fact that boolean
expressions evaluate to '1' for true, and '0' for false.

  Regards,
    Jerry

MySQL, SQL
Thread
Speed problems.. StillRichard Baskett15 Aug
  • Re: Speed problems.. StillKeith C. Ivey15 Aug
    • Re: Speed problems.. StillRichard Baskett15 Aug
      • Re: Speed problems.. StillKeith C. Ivey15 Aug
        • Re: Speed problems.. StillRichard Baskett15 Aug
          • Re: Speed problems.. StillKeith C. Ivey15 Aug
            • Combining queriesRichard Baskett15 Aug
              • Re: Combining queriesPaul DuBois15 Aug
          • Re: Speed problems.. StillBenjamin Pflugmann15 Aug
      • Re: Speed problems.. StillSimon Windsor15 Aug
  • Re: Speed problems.. StillRahadul Kabir15 Aug
    • Re: Speed problems.. StillRichard Baskett15 Aug
Re: Combining queriesJerry van Leeuwen15 Aug