• zicado (11/30/2015)


    I still don't understand (SELECT AVG(VALUE_COMISS) FROM

    COMISSION WHERE JOB.ID = COMISSION.ID)...Could someone explain this to a noob??

    It's called a correlated subquery. Basically, for each ID in the JOB table it will get the average for VALUE_COMISS. Then it will compare it to 2340.00.

    This condition will return only jobs which average commission is greater than 2340.

    Isn't PRIMARY KEY (ID, MONTH) in the wrong position???What does (ID, MONTH) mean??

    This isn't in the wrong place, it needs to be included after both columns are defined and the common practice is to put it at the end so you don't have to look for it between columns. This is called a compound key and it means that ID or MONTH can be repeated, but when combined they will give a unique value that will identify the row.

    What is JOB.ID and COMISSION.ID??

    JOB.ID is the Primary key for the table JOB. COMISSION.ID is a Foreign key that references the primary key in JOB.

    If possible could you suggest a good SQL course so I can get good at it soon?

    Try reading the stairways on T-SQL and Data in this site. http://www.sqlservercentral.com/stairway/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2