如何返回带有count的0值行

时间:2015-02-01 23:27:33

标签: sqlite

我有2张桌子,而且我应该每天保留红船的数量

我让它只返回非0的值,我无法弄清楚如何包含0

我的查询

select r.day, count(distinct r.bname)
from reservation r, boat b
where r.bname = b.bname and color = 'red'
group by day

此查询打印出所有返回非零值的行

如何包含零值?

我尝试过使用左连接但没有运气......或者可能是我做错了

  Table    Attributes

  sailor| sname   rating
           Brutus  1
           Andy    8
           Horatio 7
           Rusty   8
           Bob     1

  boat|bname        color   rating
       SpeedQueen   white    9
       Interlake    red      8
       Marine       blue     7
       Bay          red      3

  reservation| sname bname     day
               Andy  Interlake Monday
               Andy  Bay       Wednesday
               Andy  Marine    Saturday
               Rusty Bay       Sunday
               Rusty Interlake Wednesday
               Rusty Marine    Wednesday
               Bob   Bay       Monday


  alldays|     day
              monday
              tuesday
              wednesday
              thursday
              friday
              saturday
              sunday

我的查询打印出来

 Monday 2
 Wednesday 2
 Sunday 1

当我需要它像这样做

 Monday 2
 Tuesday 0
 Wednesday 2
 Thursday 0
 Friday 0
 Saturday 0
 Sunday 1

我理解,因为sqlite3不返回空值,我需要进行连接才能获得这些值?但我试过它不工作

0 个答案:

没有答案