-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: HQL question
PostPosted: Tue Apr 20, 2004 6:54 pm 
Newbie

Joined: Tue Apr 20, 2004 6:41 pm
Posts: 2
Greetings, HQL wizards. I'm looking for a single HQL query to solve this problem.

I have a table called Charge. It has cols for amount, borrower, and lender. A user can be both a borrower and lender.

I want to find the balance between user1 and user2, from the perspective of user 1. For example, for the table:

Code:
borrower   lender   balance
----------   --------  ---------
bruce        neil       10
neil           bruce    5
neil           bruce    2



should return the scalar '3'

given the parameters "neil" and "bruce"

because Bruce borrowed 10 from Neil, and Neil borrowed 5 and 2 from Bruce.

Does anyone have a single query silver bullet?



Further, can you do an HQL query that finds the balance with all users, given a user? (Will the single user case work with group by)?



Thanks in advance.
-Bruce Tate[/code]

_________________
------------------------------------
When in doubt, paddle like Hell


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 4:15 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
How to you do that in SQL?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 10:20 am 
Newbie

Joined: Tue Apr 20, 2004 6:41 pm
Posts: 2
emmanuel wrote:
How to you do that in SQL?


I'm not 100% sure that you can. (I know how to do it with a single view and a query, though...)

_________________
------------------------------------
When in doubt, paddle like Hell


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.