List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:August 11 1999 5:11pm
Subject:Re: SQL select question
View as plain text  
On Wed, 1999-08-11 10:07:16 -0700, Bill Gerrard wrote:
> mysql> explain acct;
> +-----------------+------------------+------+-----+---------+-------+
> | Field           | Type             | Null | Key | Default | Extra |
> +-----------------+------------------+------+-----+---------+-------+
> | date_created    | date             | YES  |     | NULL    |       |
> +-----------------+------------------+------+-----+---------+-------+
[...]
> Can someone suggest a select to provide a summary of records per date 
> created for a range of dates, instead of checking each one individually 
> as I've done above?
> 
> With desired output like:
> 
> +--------------+----------+
> | date_created | count(*) |
> +--------------+----------+
> | 1999-08-09   |       21 |
> +--------------+----------+
> | 1999-08-10   |       46 |
> +--------------+----------+

  SELECT date_created, COUNT(*) AS number
  FROM acct
  GROUP BY date_created;

The results are not necessarily sorted, so you might add an ORDER BY:

  SELECT date_created, COUNT(*) AS number
  FROM acct
  GROUP BY date_created
  ORDER BY date_created;

Using the alias "number" is not needed, but may be handy for accessing
the results.

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
Thread
SQL select questionBill Gerrard11 Aug
  • Re: SQL select questiontonu-mysql11 Aug
    • Re: SQL select question (THANKS)Bill Gerrard11 Aug
      • Oracle to mySQL migrationRichard M. Feezel11 Aug
        • Oracle to mySQL migrationsinisa12 Aug
  • Re: SQL select questionMartin Ramsch11 Aug
RE: SQL select questionBill Gerrard12 Aug
  • Re: SQL select questionMartin Ramsch12 Aug