存储过程中 group by 的情况

发布于 2024-08-25 07:58:37 字数 201 浏览 5 评论 0原文

是否可以在组中处理一个案例? 与此类似:

select * from table

    GROUP BY 
      CASE WHEN @Attivita=0 THEN (RANK() OVER (GROUP BY Nome,AccountID,Matricola DESC))   

     END

谢谢

is possible do a case in a group by?
similar to this:

select * from table

    GROUP BY 
      CASE WHEN @Attivita=0 THEN (RANK() OVER (GROUP BY Nome,AccountID,Matricola DESC))   

     END

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宁愿没拥抱 2024-09-01 07:58:38

您必须按所有选定的(非聚合)列进行分组。

因此,如果您选择*,您将需要按所有这些列进行分组...

如果不是group by 你的意思是order by 那么是的,你可以..

you have to group by all selected (non-aggregated) columns..

so if you select * you will need to group by all of them ...

If instead of group by you mean order by then yes you can..

甜妞爱困 2024-09-01 07:58:38

不:这没有任何意义。

您不能

  • 使用 GROUP BY 和 SELECT *
  • 在子条款中
  • 使用 RANK在 OVER 子句中使用 GROUP BY
  • 排名函数上的 GROUP BY 没有任何意义

您想做什么,请使用输入/输出和模式。

根据加比的回答进行编辑

select
   *
from
    (
    SELECT
        *, RANK() OVER (GROUP BY Nome,AccountID,Matricola DESC) as bar
    from
        table
    ) foo
ORDER BY
   CASE WHEN @Attivita=0 THEN bar END

No: this would make no sense.

You can't

  • use GROUP BY and SELECT *
  • use RANK in a subclause
  • use GROUP BY in the OVER clause
  • GROUP BY over a ranking function makes no sense

What are you trying to do, with input/output and schema please.

Edit, based on gaby's answer

select
   *
from
    (
    SELECT
        *, RANK() OVER (GROUP BY Nome,AccountID,Matricola DESC) as bar
    from
        table
    ) foo
ORDER BY
   CASE WHEN @Attivita=0 THEN bar END
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文