| Need Query, but cant test it... [message #569957] |
Sat, 03 November 2012 14:06  |
 |
IndelibleMarker
Messages: 1 Registered: November 2012
|
Junior Member |
|
|
Hi everyone, I really hope you can help me on this one...
I have no access to oracle (I'm getting on a plane at the moment), but I need a query for a database, but obviously can't test it or get my head around it without it in front of me.
I need a query which displays all the shareholders who sold shares they don't own from a table in which all share amounts are written as positive numbers, they are associated with a trade type field where 1=buy and 2=sell.
Therefore I need the query to check the transaction times of all previous trades and return the trades where the sum of the share amounts for the previous trades for a shareholder on a particular share is a negative number.
I know I need to put a call to make the share amounts positive or negative before they are summed:
Select
shareid, transactiontime, shareholderid
CALL (transactiontype,
2, 0-shareamount,
1, shareamount,
End)
From
Trades
and also check back on the transaction times for the shares share amounts for shareholders:
a select on the final info needed from trades here, then...
Select
(Sum(share amount IN (the above call select)
FROM
Trades T2
ON
T.tradeID = T2.TradeID
where
T.transactiontime < t2.transactiontime) < 0
Sorry for the mistakes, bad formatting and lack of info/schema, but if someone could put this together into a working (or nearly working!) Query, I'd really, really appreciate it because I'm still relatively new to SQL.
Thanks everyone!
Thanks in advance
|
|
|
|
|
|
|
|