View Single Post

   
  #7 (permalink)  
Old 03-28-2008, 04:40 AM
Michael Austin
 
Posts: n/a
Default Re: need help on sql

Junkone wrote:
> On Mar 20, 10:04 pm, Michael Austin <maus...@firstdbasource.com>
> wrote:
>> Junkone wrote:
>>> i have 3 tables which are linked to 1 another using foreigh key-
>>> Trades, executions, rawdatas with id as primary key
>>> Trades can have 1 or more executions
>>> Executions must have only 1 rawdatas
>>> The structure is
>>> Rawdatas cols
>>> 1. id
>>> 2. Date
>>> 3. col2
>>> 4. col3
>>> Executions.
>>> 1. id
>>> 2. EntryOrExit
>>> 3. col2
>>> 4. col3
>>> Trades
>>> 1. id
>>> 2. col1
>>> 3. col2
>>> 4. col3
>>> I want to build a query which returns all the trades and return the
>>> value of RawDatas.date where Executions.EntryorExit="Entry"
>>> i need some help.
>>> seede

>> Please post what you have tried. We can help, but would like to see
>> where you are going wrong.. and if this is homework you should be
>> figuring this out for yourself and not having others do it for you...(I
>> doubt any real trading company would hire someone to do this in MySQL -
>> especially someone who shows very little knowledge of SQL for something
>> this simple...)- Hide quoted text -
>>
>> - Show quoted text -

>
> select r.created_at,t.* from trades t, executions e, rawdatas r where
> r.execution_id=e.id and e.trade_id=t.id
> and e.entryorexit='ENTRY'
>
> The # of rows in Trades=353. The rows returned by this sql is 409
> because there are 1:n relationshiop between Trades and Executions. I
> just wanted the values form the first record from executions that is
> related to Trades. I would really appreciate some help here because i
> can go only so far.
> PS: This is not homework. I am a starter programmer doing some work
> for a smalltime company.



Good luck. Only advice I can give is for you to spend every waking hour
for the next few weeks reading, researching and testing - get yourself a
Linux box at home - Fedora or most any of the downloadable Linux
distro's come with MySQL included and research research then test test
and test some more...
Reply With Quote