0

Is it possible in PostgreSQL to select one column from a table within a particular date span (there is a date column) and - here is the catch! - add the table together. Like for making a sales report?

7
  • Can you post an example of what you are trying to do? Commented Aug 8, 2012 at 20:09
  • Please provide sample data and desired output. Commented Aug 8, 2012 at 20:13
  • @RedFilter absolutely. two minutes. Commented Aug 8, 2012 at 20:14
  • SELECT amount FROM sales_orders WHERE date BETWEEN 11-03-06 & 11--04-06 and add them together... Commented Aug 8, 2012 at 20:18
  • INSERT INTO tbl_a SELECT date_fld FROM tbl_b WHERE CAST(date_fld AS DATE) BETWEEN '2012-01-01' AND '2012-01-31' but it sounds you may want a join? Commented Aug 8, 2012 at 20:22

2 Answers 2

1

Based on your comment, I think you are referring to SUM(). This is an aggregate function

SELECT SUM(amount)
FROM sales_orders 
WHERE date BETWEEN '2011-03-06' and '2011-04-06' -- not sure what your date is.
Sign up to request clarification or add additional context in comments.

7 Comments

oops..meant to post this comment to you : razorsql asked me to enter a parameter value for & ..what does that mean?
@thomas you need to use AND between your dates not &.
@thomas you need to place you dates in the correct format yyyy-mm-dd
Please link to the current version of the manual. Postgres 8.1 has been out of business for quite a while now. If you don't need to address a particular version, it's probably best to point to http://www.postgresql.org/docs/current/interactive/.
@ErwinBrandstetter agreed. That was the link I got when I tried to find aggregate function. I should have verified it was functioning when I posted. Thanks for the edit.
|
0

If I understand you correctly, you are looking for this:

SELECT sum(amount) 
FROM sales_orders 
WHERE date ...

1 Comment

my razorsql asked me to enter a parameter value for & ..what does that mean?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.