Menu

12 Eylül 2010 Pazar

Cok sutunlu altsorgular

Altsorgunun SELECT kisminda birden fazla sutun yer aliyorsa bunlara cok sutunlu alt sorgular denir. Cok sutunlu alt sorugular  genelde sutunlarin karsilastirilmasinda kullanilir yada UPDATE  cumlelerinde kullanilir.

Asagidaki sorgudaki her departmende en yuksek maasi alan employee listelenmistir..

select concat(first_name,' '|| last_name) AS fullname, salary, department_id from employees
    WHERE (department_id, salary) IN
          (SELECT department_id, max(salary)
              FROM employees GROUP BY department_id)
    ORDER BY salary DESC


FULLNAME                                       SALARY                 DEPARTMENT_ID         
---------------------------------------------- ---------------------- ----------------------
Steven King                                          31944                  90                    
John Russell                                          18634                  80                    
Nancy Greenberg                                 15982.65               100                   
Shelley Higgins                                     15982.65               110                   
Den Raphaely                                      14641                  30                    
Hermann Baer                                     13310                  70                    
Alexander Hunold                               11979                  60                    
Adam Fripp                                        10914.2                50                    
Susan Mavris                                      8651.5                 40                    
Pat Fay                                              7986                   20                    
Jennifer Whalen                                  5856.4                 10                    

11 rows selected

Hiç yorum yok:

Yorum Gönder