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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help me out - complicated query

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi. Do you think this is possible?

Here is my sample table:
Line Data Primary Description Amount
1 A1 x test1 1
2 A1 test2 3
3 A1 test3 2
4 B1 y testb1 5
5 B1 testb2 5
6 B1 testb3 5

Here is what I need for the results:
Data Primary Description Amount
A1 x test1 6
B1 y testb1 15

(I need Line 1 to 3 to total up the amount with
a distinct line 1 [with the character in primary
column] and Line 4 to 6 to total up the amount
with a distinct line 4)

Is this possible? If so, how would I go about to achieve this results? I am able to total up the amount with distinct data, however i would not get primary and description. how can i include primary and description as well?

Thank you so much for your help!

Angelina
 
Hi Angelina,
assuming your table name is Table1, the following query will do it for you;

Code:
SELECT Table1.data AS Data,First(Table1.primary) AS Primary, First(Table1.description) AS Description, Sum(Table1.amount) AS Amount
FROM Table1
GROUP BY Table1.data
ORDER BY First(Table1.primary);

Regards,
Shemzar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top