zoukankan      html  css  js  c++  java
  • --三种方法查询人所在部门平均工资

    --建表

    IF OBJECT_ID(N'Emp','U') IS NOT NULL

        BEGIN

            PRINT 'This table have been existed';

           

        END

    ELSE

        BEGIN

            CREATE TABLE [dbo].[Emp]

            (

                [Name]       NVARCHAR(50) ,

                [Slary]      INT,

                [DepID]      INT

              

            )

     

             INSERT INTO [Emp]

               SELECT N'张三', '100', 1

               UNION ALL

               SELECT N'李四', '200', 1

               UNION ALL

               SELECT N'王五', '200', 2

               UNION ALL

               SELECT N'张麻子', '300', 2

               UNION ALL

               SELECT N'一柱擎天', '300', 2

               UNION ALL

               SELECT N'陈勃', '400', 3

                 

        END

    -------------------------------------------------------------------------------------------------------------------------

    --方法:Nested Loop

    SELECT a.*,(SELECT AVG(Slary) FROM [Emp] b WHERE b.DepID=a.DepID ) 

      FROM [Emp] a

    --方法:开窗

    SELECT *, AVG(Slary) OVER(PARTITION BY DepID)

      FROM [Emp] 

    --方法:

    SELECT a.*, b.Avg

      FROM [Emp] a INNER JOIN (SELECT DepID, AVG(Slary) Avg FROM [Emp] GROUP BY DepID) b ON a.DepID=b.DepID 

  • 相关阅读:
    OleView.exe:查看机器上的COM 组件。
    COM中导出GUID
    进程外组件以及进程间通信方式
    拼接多个 wchar_t *
    wstring to wchar_t*
    BSTR
    GetProcAddress 使用注意事项
    C++和.net的集合类对应
    COM的一些基本概念
    Error Lookup工具
  • 原文地址:https://www.cnblogs.com/sthinker/p/5735259.html
Copyright © 2011-2022 走看看