0

これが私のクエリです:

select COUNT(*) as total, COUNT(distinct user) as unique 
FROM table 
WHERE uristem in ('/example/', '/example/', '/example/', '/example/') 
      and time > DATE_SUB(NOW(), INTERVAL 24 HOUR)' 
group by uristem;

このように見えるはずです

100 50
25  50
0   0
100 35

でもカウントが無いとこんな感じ(抜けてる)

100 50
40  50
100 35

代わりに 0 を埋めるにはどうすればよいですか?

4

2 に答える 2

1

URI ステムを含むテーブルがない場合は、次のような醜いものがあります

Select
  u.uristem,
  count(t.uristem),
  count(distinct t.user) as unique
From (
    Select '/example1/' As uristem
    Union All Select '/example2/'
    Union All Select '/example3/'
    Union All Select '/example4/'
  ) u
    Left Outer Join
  table t
    On u.uristem = t.uristem And
    t.time > Date_Sub(Now(), Interval 24 Hour)
 Group By
   u.uristem

やるべき

于 2012-11-13T00:05:43.493 に答える
1

これを試してください(テストされていません):

select COUNT(t.uristem) as total
, COUNT(distinct t.user) as unique 
FROM 
    (
        select uristem, user
        from table
        where time > DATE_SUB(NOW(), INTERVAL 24 HOUR) 
    ) t
right outer join 
(
    select '/example/' x
    union select '/example/'
    union select '/example/'
    union select '/example/'
) y
on t.uristem = y.x
group by y.x;
于 2012-11-13T00:05:46.827 に答える