4

こんな問い合わせがあります

SELECT COUNT(u.user_id) AS count1 FROM users WHERE user_id>1001 
UNION
SELECT COUNT(c.hits) AS count2 FROM source c WHERE loginid LIKE 'fb%';

結果

count1 
250
56

どうやったらこんな風に一列にできるんだろう

count1   count2
250      56
4

2 に答える 2

5

サブクエリを使用してこれを実現できます。

select 
      (SELECT COUNT(u.user_id) AS count1 from users where user_id>1001) as count1,
      (select count(c.hits) AS count2 from source  c where loginid like 'fb%') as count2
于 2012-08-22T06:19:43.633 に答える
1
SELECT SUM(count1) AS count1,
       SUM(count2) AS count2
FROM(
    SELECT COUNT(u.user_id) AS count1, 0 AS count2 from users where user_id>1001

    UNION ALL

    SELECT 0 AS count1, count(c.hits) AS count2 from source  c where loginid like 'fb%';
)a;
于 2012-08-22T06:21:52.460 に答える