USE ssb1; select format(count(lo_orderdate), 0) num_days, format(min(lo_orderdate), 0), format(max(lo_orderdate), 0), format(avg(daily_cnt), 0) avg_rows_per_day, format(sum(daily_cnt), 0) total_rows, format(sum(daily_cnt * d_lastdayinweekfl), 0) total_sales_last_day_in_week, format(sum(daily_cnt * d_lastdayinmonthfl), 0) total_sales_last_day_in_month, format(sum(daily_cnt * d_holidayfl), 0) total_sales_on_holidays, format(sum(daily_cnt * d_weekdayfl), 0) total_weekday_sales, format(sum(case when d_weekdayfl = 0 then daily_cnt else 0 end), 0) total_weekend_sales from (select lo_orderdate, count(*) daily_cnt from lineorder where lo_orderdate in (19920102,19920101,19930101) group by 1) a, dateinfo where d_datekey = lo_orderdate; num_days format(min(lo_orderdate), 0) format(max(lo_orderdate), 0) avg_rows_per_day total_rows total_sales_last_day_in_week total_sales_last_day_in_month total_sales_on_holidays total_weekday_sales total_weekend_sales 3 19,920,101 19,930,101 2,402 7,207 2,366 7,207 4,863 4,841 2,366 select count(lo_orderdate) num_days, min(lo_orderdate), max(lo_orderdate), avg(daily_cnt) avg_rows_per_day, sum(daily_cnt) total_rows, sum(daily_cnt * d_lastdayinweekfl) total_sales_last_day_in_week, sum(daily_cnt * d_lastdayinmonthfl) total_sales_last_day_in_month, sum(daily_cnt * d_holidayfl) total_sales_on_holidays, sum(daily_cnt * d_weekdayfl) total_weekday_sales, sum(case when d_weekdayfl = 0 then daily_cnt else 0 end) total_weekend_sales, format(count(lo_orderdate), 0) num_days, format(min(lo_orderdate), 0), format(max(lo_orderdate), 0), format(avg(daily_cnt), 0) avg_rows_per_day, format(sum(daily_cnt), 0) total_rows1, format(sum(daily_cnt * d_lastdayinweekfl), 0) total_sales_last_day_in_week, format(sum(daily_cnt * d_lastdayinmonthfl), 0) total_sales_last_day_in_month, format(sum(daily_cnt * d_holidayfl), 0) total_sales_on_holidays, format(sum(daily_cnt * d_weekdayfl), 0) total_weekday_sales, format(sum(case when d_weekdayfl = 0 then daily_cnt else 0 end), 0) total_weekend_sales from (select lo_orderdate, count(*) daily_cnt from lineorder where lo_orderdate in (19920102,19920101,19930101) group by 1) a, dateinfo where d_datekey = lo_orderdate; num_days min(lo_orderdate) max(lo_orderdate) avg_rows_per_day total_rows total_sales_last_day_in_week total_sales_last_day_in_month total_sales_on_holidays total_weekday_sales total_weekend_sales num_days format(min(lo_orderdate), 0) format(max(lo_orderdate), 0) avg_rows_per_day total_rows1 total_sales_last_day_in_week total_sales_last_day_in_month total_sales_on_holidays total_weekday_sales total_weekend_sales 3 19920101 19930101 2402.3333 7207 2366 7207 4863 4841 2366 3 19,920,101 19,930,101 2,402 7,207 2,366 7,207 4,863 4,841 2,366 select count(lo_orderdate) num_days, sum(daily_cnt * d_lastdayinweekfl) ##-- ,format(cast(sum(daily_cnt * d_lastdayinweekfl) as char), 0) total_sales_last_day_in_week from (select lo_orderdate, count(*) daily_cnt from lineorder where lo_orderdate in (19920102,19920101,19930101) group by 1) a, dateinfo where d_datekey = lo_orderdate; num_days sum(daily_cnt * d_lastdayinweekfl) 3 2366 select count(lo_orderdate) num_days, sum(daily_cnt * d_lastdayinweekfl) ,format(cast(sum(daily_cnt * d_lastdayinweekfl) as char), 0) total_sales_last_day_in_week from (select lo_orderdate, count(*) daily_cnt from lineorder where lo_orderdate in (19920102,19920101,19930101) group by 1) a, dateinfo where d_datekey = lo_orderdate; num_days sum(daily_cnt * d_lastdayinweekfl) total_sales_last_day_in_week 3 2366 2,366