sql - HQL count() with group by not returning zero/0 records -


string query = "select hour(la.datelastupdated) hour,"  + "coalesce(count(la), 0) loginactivity la"  + "where la.datelastupdated > :date"  + "group hour(la.datelastupdated)"  + "order hour(la.datelastupdated)";  date date = new date(system.currenttimemillis() - 12*60*60*1000)); 

result i'm getting like

hour  count ----  ----- 12    1 13    3 15    4 17    11 

but want result like

hour  count ----  ----- 12    1 13    3 14    0 15    4 16    0 17    11 

that means 0 counts. tried coalesce it's not working. probable hql query expected result? native query do.

*i'm using postgresql database

if record want (for example hour = 14) not exist in loginactivity table, how can expect show in resultset?

i assume want list every hour of day , record counts based on that; if case

  1. you need dictionary-like structure includes every hour of day begin with,
  2. you need execute left outer join structure resultset, joining on field hour.

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -