zoukankan      html  css  js  c++  java
  • SQL语句和EF Group by 用法

    1,Group by 根据某个字段排序

           select Department,count(*) FROM [PPMG].[dbo].[UnConViolation] group by Department

    结果如下:

    2,Group by与所传参数联合使用

    USE PPMG
    
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    Alter PROCEDURE UnConViolationTimes 
        @type nvarchar(50)
    AS
    BEGIN
        declare @sql nvarchar(1000)
        if @type is not null
        begin
          set @sql='select '+ @type+' as Name,count(*) as Count FROM [PPMG].[dbo].[UnConViolation] group by '+@type
          print @sql
          exec(@sql)
        end    
    END
    GO

    exec UnConViolationTimes 'Department'

    结果如下

    3,Group by 后台用法

    public List<ViolationTimesDto> GetUnConViolationTimes(string type)
            {
                var UnConViolationList = UnConViolationRepository.Query();
    
                var ttList = UnConViolationList.GroupBy(m => new { m.Department}).Select(m => new ViolationTimesDto()
                {
                    Name=m.Key.Department,
                    Count=m.Count()
                }).ToList();            
                return ttList;
            }        

     结果如下

  • 相关阅读:
    ASP.NET 5
    asp.net web api
    PowerShell 常用命令
    WinDbg
    Visual Studio Online
    asp.net authentication
    CoreOS
    解决download.msdn.microsoft.com无法正确解析而无法下载的问题
    nodejs express
    移动平台WEB前端开发技巧汇总
  • 原文地址:https://www.cnblogs.com/lcidy/p/10619193.html
Copyright © 2011-2022 走看看