2个计数并将结果组合为一列| SQL Server Management Studio

发布于 2025-02-10 03:16:15 字数 715 浏览 0 评论 0原文

我试图根据某些登记日期和创建日期在数据库中对数据库中的不同ID进行计数。

tables:
 - people p
 - number n
 - message m
 - volume v

要求

  • 在链接到ID的数字的情况下; 最古老的数字之间的时间registrationDateTime和Message.CreationDateTime< = 10 wd

  • ,如果链接到ID的音量(和没有数字); 最古老的数字之间的时间registrationDateTime和Message.CreationDateTime< = 10 wd

均应总计计数为

查询的我计数:

  • count(case cast deDiff(dw,dw,n.RegistrationDateTime,m.creationdateTime,m.creationdateTime)< lt; = 10然后p.id end作为a
  • ,count(dw,dw,v.registrationDateTime,m.creationdatetime)< = 10 then p.id end as a

我的问题;

  • 我如何结合2个计数的总数,该计数将显示在“ A”列中

Im trying to do a count of distinct Id's of people in a database based on some registrationdate and creationdate.

tables:
 - people p
 - number n
 - message m
 - volume v

Requirements

  • In case of a number linked to the Id;
    the time between the oldest number.registrationdatetime and message.creationdatetime <= 10 wd

  • In case of a volume (and no number) linked to the Id;
    the time between the oldest number.registrationdatetime and message.creationdatetime <= 10 wd

Both should be counted in total as A

my count part of the query:

  • count (case when datediff(dw, n.registrationdatetime , m.creationdatetime) <=10 then p.id end as A
  • ,count (case when datediff(dw, v.registrationdatetime , m.creationdatetime) <=10 then p.id end as A

my question;

  • How do I combine the 2 counts for a total that will be displayed in column "A"

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文