Results 1 to 3 of 3

Thread: Sql Query with Total

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    Sql Query with Total

    Hi guys,

    I can't do this in sql query.

    Code:
    Site	Capital	     TotalCapital
    Site A	1,995,000	2,229,500
    Site A	234,500	
    Site B	4,320,234	4,320,234
    Site C	2,381,354	2,504,766
    Site C	123,412
    The query will sum up if the site is the same. Is this possible in sql query? Or do I really need crystal report to accomplish this?

    Code:
    Site	Capital	     TotalCapital
    Site A	1,995,000	
    Site A	234,500	
                           2,229,500
    Site B	4,320,234	
                           4,320,234
    Site C	2,381,354	
    Site C	123,412
                           2,504,766
    And also to use the totalcapital result in a formula to add taxes. Thanks in advance.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Sql Query with Total

    You can't get the format you want from an SQL statement, you would need some client side code (your own, or what is built into something like Crystal).

    You could however get data like this easily:
    Code:
    Site	TotalCapital
    Site A	2,229,500
    Site B	4,320,234
    Site C	2,504,766
    To do that you simply need a Group By, eg:
    Code:
    SELECT Site, Sum(Capital) as TotalCapital
    FROM tablename
    GROUP BY Site

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    Re: Sql Query with Total

    I'll try to use Crystal Report, thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width