sql - Select a default for missing rows in mysql -


i have simple table keep count of number of visitors on website.

|day|visitors| |1  |2       | |2  |5       | |4  |1       | 

i want select number of visitors per day days 1 4, want value day 3. since day 3 missing, wonder if possible select integers in range, , if column missing, default returned. simple "select visitors table day >= 1 , day <= 4 order day" query return "2, 5, 1", query i'm looking return "2, 5, 0, 1".

here example data:

select n.n days, coalesce(visitors, 0) visitors (select 1 n union select 2 union select 3 union select 4      ) n left outer join      t      on t.days = n.n; 

you need fill in numbers of days in n subquery. perhaps have table sequential numbers can , other queries.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -