From: | "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com> |
---|---|
To: | taizi <taizi2006blog(at)163(dot)com>, pgsql-admin(at)postgresql(dot)org |
Subject: | Re: How to query by month? |
Date: | 2016-11-29 17:00:05 |
Message-ID: | 642f883e-7f57-bf82-6f36-753d0e0eeb0d@commandprompt.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On 11/29/2016 06:08 AM, taizi wrote:
> Hi all,
> im a beginner for SQL, and trying to use it with my daily work.
> Now i catched this question(my title of mail).
> Suppose there is a table about orders, i want to sum the total amount of
> each month.
> There was a statement of mine to november.
> select sum(order_amount) FROM table_name WHERE order_date between
> '2016-11-01' AND '2016-11-30';
> I know it comes a result what i want, but i hope someone can tell me
> another way to use.
> After searched, i found there is a function named date_part, but it
> doesn't work.
select sum(order_amount) from table_name where date_part('month',
order_date) = '$month';
Note that the $month will be the month number, not name. So for
November, it will = 11.
JD
> thanks for any help!
> Leopold
>
>
>
>
>
--
Command Prompt, Inc. http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.
From | Date | Subject | |
---|---|---|---|
Next Message | Achilleas Mantzios | 2016-11-30 07:32:28 | Re: how to upgrade from 8.4 to 9.2 |
Previous Message | Marc Fromm | 2016-11-29 15:57:00 | how to upgrade from 8.4 to 9.2 |