从一个结果集中的多个表中选择 count(*)

发布于 2024-11-04 02:53:16 字数 467 浏览 1 评论 0原文

我如何为具有其他字段的 30 个表选择 count(*)。

我想应用限制,例如时间限制。我有诸如 statemasterdealermasterbusinessdetail 之类的表。

我想要相应的 statecodestatename 的结果。

我想要的输出如下:-

statecode statename count(*) for dealermaster count(*) for business details
01        ca         25                        20
01        au         30                        35

statecode,statemaster 表中的 statename

How I can select count(*) for 30 tables with other fields.

I want to apply restriction like time constraint. I have tables like statemaster, dealermaster, businessdetail.

I want results for respective statecode, statename.

i want output like:-

statecode statename count(*) for dealermaster count(*) for business details
01        ca         25                        20
01        au         30                        35

statecode, statename from statemaster table

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

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

发布评论

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

评论(1

梦毁影碎の 2024-11-11 02:53:16

虽然这听起来像是一个奇怪的请求,但无论如何我都会提供一个答案,看看你如何处理它。

您应该能够使用一堆相关子查询来获取这些结果,如......

SELECT S.statecode,
       S.statename,
       (
              SELECT COUNT(*)
              FROM dealermaster DM
              WHERE DM.statecode = S.statecode
       ) AS COUNT1,
       (
              SELECT COUNT(*)
              FROM businessdetail BD
              WHERE BD.statecode = S.statecode
       ) AS COUNT2
FROM statemaster S
GROUP BY S.statecode, S.statename

Whilst this sounds like an odd request, I'll provide an answer anyway and see how you get along with it.

You should be able to use a bunch of correlated subqueries to obtain these results, as in...

SELECT S.statecode,
       S.statename,
       (
              SELECT COUNT(*)
              FROM dealermaster DM
              WHERE DM.statecode = S.statecode
       ) AS COUNT1,
       (
              SELECT COUNT(*)
              FROM businessdetail BD
              WHERE BD.statecode = S.statecode
       ) AS COUNT2
FROM statemaster S
GROUP BY S.statecode, S.statename
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文