You need to expose date_ts in the projected columns.
select to_date(date_ts) date_ts, sum(if(col1 = 'type1', 1, 0)) as type_1, sum(if(col1 = 'type2', 1, 0)) as type_2, sum(if(col1 = 'type3', 1, 0)) as type_3 from table1 WHERE unix_timestamp(date_ts) >= unix_timestamp('2011-10-01 00:00:00.178-01') AND unix_timestamp (date_ts) <= unix_timestamp('2011-10-05 23:59:59.168-08') GROUP BY col1, TO_DATE(date_ts) ORDER BY date_ts;'