Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accumulate a value 1

Status
Not open for further replies.

jacom

Programmer
Mar 26, 2001
6
0
0
DE
Hallo, could somebody help me in this SQL-Problem?

My table contains the following columns:
Invoicenumber / Articlenumber / Quantity / Text

Records should be added in the column Quantity, when the Invoicenumbers are identical and Articlenumber are identical.

Example:
INVNO / ARTNO / QUAN / TEXT
4711 / 312 / 3 / Table
4711 / 434 / 6 / Chair
4711 / 312 / 2 / Table
4712 / 312 / 7 / Table

The result should be:
4711 / 312 / 5 / Table
4711 / 434 / 6 / Chair
4712 / 312 / 7 / Table

Thanks for help
Didi


 
Try
select invno, artno, sum(qty) qty, text
from your_table
group by invno, artno, text
/

The sum command will add up all the qty coloumn, the group by groups up rows for the sum operation, in this case all rows where the invno, artno and text are the same.

HTH,

Mike.
 
Thank you Mike,
your answer show me the way to the solution of my problem.
I have more columns in my database, and I need their in my sql-result, e.g. a text-column "text2".

I use this sql:

select invno, artno, sum(qty) qty, max(text) text, max(text2) text2 from your_table group by invno, artno

Didi

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top