User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 401,615 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,700 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.

Urgent Help with SQL Query

Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Urgent Help with SQL Query

  #2  
Apr 19th, 2006
I don't use mysql but both of these work in ms-sql:
query 1:
declare @buyerid int
set @buyerid = 2
declare @creds int
declare @debs int

set @creds =(select sum(credits) from Transactions where buyerid = @buyerid and value >0)
set @debs =(select sum(credits) from Transactions where buyerid = @buyerid and value =0)
select (@creds - @debs) as Balance

query 2:
declare @buyerid int
set @buyerid = 2
select (Sum(t1.credits) - Sum(t2.credits)) as Balance
from transactions t1, transactions t2 where
t2.buyerid = @buyerid and t1.buyerid = @buyerid and t1.value > 0 and t2.value = 0
Reply With Quote  
All times are GMT -4. The time now is 5:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC