pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joshua D. Drake <jd@commandprompt.com>
To: taizi <taizi2006blog@163.com>
To: pgsql-admin@postgresql.org
Subject: Re: How to query by month?
Date: Tue, 29 Nov 2016 09:00:05 -0800
Message-ID: <642f883e-7f57-bf82-6f36-753d0e0eeb0d@commandprompt.com> (raw)
In-Reply-To: <35257d1c.b253.158b06aaae5.Coremail.taizi2006blog@163.com>
References: <35257d1c.b253.158b06aaae5.Coremail.taizi2006blog@163.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.


-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin



view thread (4+ messages)

Message-ID: <642f883e-7f57-bf82-6f36-753d0e0eeb0d@commandprompt.com>
Permalink:  ../642f883e-7f57-bf82-6f36-753d0e0eeb0d@commandprompt.com/
Also on:    postgresql.org/message-id/642f883e-7f57-bf82-6f36-753d0e0eeb0d@commandprompt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: jd@commandprompt.com, taizi2006blog@163.com
  Subject: Re: How to query by month?
  In-Reply-To: <642f883e-7f57-bf82-6f36-753d0e0eeb0d@commandprompt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox