Article View: microsoft.public.msaccess.chat
Article #2Re: Challange: How do I sum data from the same table in an SQL query???
From: John Peterson
Date: Sun, 03 Oct 1999 00:00
Date: Sun, 03 Oct 1999 00:00
57 lines
2416 bytes
2416 bytes
Brad,
You might try something like:
select substring(AccountNum, 1, datalength(AccountNum) - 1),
sum(Amount)
from YourTable
group by substring(AccountNum, 1, datalength(AccountNum) - 1)
(BTW: The substring might be overkill, but I wasn't sure how your
AccountNum data was structured.)
Hope this helps!
John Peterson
Brad <brad@xspace.com> wrote in message
news:rvft69ktmom67@corp.supernews.com...
> Hmm. I thought this would be easy.
>
> In Microsoft Access I have a set of data that looks like this:
>
> AccountNum Amount
> 2000A 12
> 2000B 3
> 4000A 50
> 4000B 40
>
> I would like to 'add-up' accounts of the same number (eg: combine the "A"
> accounts with the "B" accounts) in an SQL query. For example, the
resulting
> table would look like:
>
> NewAccountNum NewAmount
> 2000 15
> 4000 90
>
> I've been trying to use a sub query that goes seomthing like:
>
> SELECT
> Amount +
> (SELECT Amount FROM table WHERE AccountNum = Left
> (AccountNum,LEN(AccountNum)-1) & "B")
>
> AS NewAmount
>
> FROM table
>
> WHERE RIGHT(AccountNum,1) <> "B"
>
> But of course my sub-query returns multple values.
> If you have any suggestions, please reply directly to brad@xspace.com
>
> Thanks!
>
>
>
Technical Details
Message-ID:
<OVzoQCgD$GA.210@cppssbbsa02.microsoft.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<rvft69ktmom67@corp.supernews.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 115df1,b17fd4d87b5087ba X-Google-Attributes: gid115df1,public X-Google-Thread: 10de66,b17fd4d87b5087ba X-Google-Attributes: gid10de66,public X-Google-Thread: 107d2f,b17fd4d87b5087ba X-Google-Attributes: gid107d2f,public X-Google-Thread: ffa7b,b17fd4d87b5087ba X-Google-Attributes: gidffa7b,public X-Google-Thread: 11301e,b17fd4d87b5087ba X-Google-Attributes: gid11301e,public From: "John Peterson" <johnp@azstarnet.com> Subject: Re: Challange: How do I sum data from the same table in an SQL query??? Date: 1999/10/03 Message-ID: <OVzoQCgD$GA.210@cppssbbsa02.microsoft.com> X-Deja-AN: 532471009 References: <rvft69ktmom67@corp.supernews.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 X-MSMail-Priority: Normal Newsgroups: microsoft.public.msaccess.chat,borland.public.delphi.database.sqlservers,microsoft.public.sqlserver,microsoft.public.sqlserver.odbc,microsoft.public.sqlserver.programming