1

2 つのテーブルがあり、両方のテーブルからカウントを取得しようとしています。最初のテーブルからカウントし、次に 2 番目のテーブルからカウントすることを意味し、結果は次のようになります。

Count(users.name)   Count(users_types)
        5                    8

しかし、私のクエリはこの結果をもたらします

Count(users.name)   Count(users_types)
        8                    8

これが私のクエリです

select count(users.users),
count(users_types.users_types)
form users , users_types  

どうすれば正しい結果を得ることができますか?

4

3 に答える 3

1
select (select count(*) cnt1 from table1),
 (select count(*) cnt2 from table2)
于 2012-04-30T12:03:47.470 に答える
1

試す:


select
(select count(users.users) from users),
(select count(users_types.users_types) form users_types)
于 2012-04-30T11:55:44.690 に答える
0

このようなサブクエリを使用します

select
  count(users.users)    Users,
  (select
     count(users_types.users_types)
   from teams)    UsersTypes
from users
于 2012-04-30T12:10:10.203 に答える