File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQLQuery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLQuery" Watch "SQLQuery" New topic
Author

SQLQuery

siva kumar
Ranch Hand

Joined: Sep 03, 2004
Posts: 86
MyTable look likes below one
-------------
Name | Sal
--------------
aa | 1000
bb | 3000
cc | 5000
-----------------


I want to dispaly the datas as like

-----------------------
Name | Sal | Total
-----------------------
aa | 1000 | 1000
bb | 3000 | 4000
cc | 5000 | 9000
------------------------



what is the sql query returning the above structure.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Which Database are you using , If you are using Oracle then you can use analytical functions of oracle, search the Google for same

you may make a query like



Hope this query helps you ... this is a sample query you need to make your own query

thanks
[ November 03, 2004: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
not working Shailesh. But i am sure there must be someway out, and somebody will get you the right query for this.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

I have just given an idea to make query ....however it was working for me at first instance on oracle 9i

hope this URL of
Calculate a running Total will put better light.

thanks
[ November 03, 2004: Message edited by: Shailesh Chandra ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874

Thanks Shailesh that link worked.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Cheers
siva kumar
Ranch Hand

Joined: Sep 03, 2004
Posts: 86
Thanks Shailesh and Adeel
Regards
rakkesh kumar
Ranch Hand

Joined: Oct 06, 2004
Posts: 37
but the query is not working in MSSQLServer

.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

rakkesh ,

query uses analytical feature of oracle , hence it will work in oracle only.

it will not work in sql server untill they provide same features

thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30146
    
150

Siva,
You could just add up the numbers in Java when iterating through the resultset and add the total column to the output then.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Jeanne Boyarsky:
Siva,
You could just add up the numbers in Java when iterating through the resultset and add the total column to the output then.


better approach. cent percent agreement.
this way doesn't matter if you change your db in future.
 
 
subject: SQLQuery
 
Similar Threads
Map Problem
Confused for threading ?
update query feasible solution
static methods and NULL
generate xml to java Bean