zoukankan      html  css  js  c++  java
  • Nhibernate Case SUM

    SELECT 
    ID
    SUM(CASE WHEN myProperty = 2 THEN 1 ELSE 0 END) as nbRowWithValueOf2,
    SUM(CASE WHEN myProperty = 3 THEN 1 ELSE 0 END) as nbRowWithValueOf3
    FROM Foo
    GROUP BY ID
    queryover = queryover
        .Select(
            Projections.Group<Foo>(c => c.ID),
            Projections.Sum(
                Projections.Conditional(
                    Restrictions.Where<Foo>(f => f.myProperty == MyEnum.Two),
                    Projections.Constant(1),
                    Projections.Constant(0))),
            Projections.Sum(
                Projections.Conditional(
                    Restrictions.Where<Foo>(f => f.myProperty == MyEnum.Three),
                    Projections.Constant(1),
                    Projections.Constant(0))));

    生成SQL

    SELECT this_.ID as y0_,
           sum((case
                  when this_.myProperty = 2 /* @p0 */ then 1 /* @p1 */
                  else 0 /* @p2 */
                end))               as y1_,
           sum((case
                  when this_.myProperty = 3 /* @p3 */ then 1 /* @p4 */
                  else 0 /* @p5 */
                end))               as y2_
    FROM   [Foo] this_
    GROUP  BY this_.ID
  • 相关阅读:
    常用的VI/VIM命令
    那些年学过的一些算法
    huffman编码
    好用java库(一):java date/time api:jodatime
    linux启动
    ubuntu学习方式
    地址
    各种各样的软件
    jquery文件
    C变量与数据
  • 原文地址:https://www.cnblogs.com/hyl8218/p/3492676.html
Copyright © 2011-2022 走看看