資料庫題——高於部門平均工資查詢問題,部門平均工資

來源:互聯網
上載者:User

資料庫題——高於部門平均工資查詢問題,部門平均工資
題目:找出高於所在部門平均工資的員工的姓名,工資,所在部門的編號,部門的平均工資

1、首先找出每個部門的平均工資

SELECT AVG(salary) pjgz,did FROM man WHERE GROUP BY did

2、將其作為暫存資料表,放到主查詢中

SELECT man.name ,man.salary ,lsb.did ,lsb.pjgz  FROM man ,(SELECT AVG(salary) pjgz,did FROM man GROUP BY did) lsb WHERE man.did =lsb.did  AND man.salary > lsb.pjgz;

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.