English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is there any way to get MySQL to run a series of Select statements that will yield quantity totals for one attribute based on multiple tuples...?

::example::
Table, Date, Store, Item Qty
Jan 2, 5, B, -4
Jan 3, 5, C, -3
Jan 3, 1, B, -1
Jan 5, 5, B, -3

I have a statement that will gives the total of item B from one store, but can't figure out a query that will give the total for item B sold by store 5 AND the total items sold by store 1....
Store 5, Item B, Qty -7
Store 1, Item B, Qty -1

2007-03-18 15:03:11 · 3 answers · asked by ? 2 in Computers & Internet Programming & Design

3 answers

Each item will be a select statement which will be in your program.

For each item you would run the select statement into a variable for later use. you then display the variable/value in the screen (Web or other program).

The select statements are 1 for 1 to each value(s) you are looking for.

2007-03-18 15:12:00 · answer #1 · answered by Jeffrey F 6 · 0 0

It has been a while since i programmed in sql, but i just did it in access according to the table you provided and it showed like this::
SELECT Table1.StoreName, Sum(Table1.ItemName) AS SumOfItems, Table1.ItemCount
FROM Table1
GROUP BY Table1.StoreName, Table1.ItemName
HAVING (((Table1.StoreName)=5) AND ((Table1.ItemName)="b")) OR (((Table1.StoreName)=1) AND ((Table1.ItemName)="b"));

The result is:
Store 1 sold -1 of item b
Store 5 sold -7 of item b.
Hope its what you want.

2007-03-18 15:25:23 · answer #2 · answered by Anonymous · 1 0

I think you may be looking for the UNION statment. a good example is here: http://www.w3schools.com/sql/sql_union.asp

2007-03-18 15:16:26 · answer #3 · answered by Noodle Head 2 · 0 1

fedest.com, questions and answers