0

I need to make a query that generates the records of each day by model, I currently create a query that generates monthly records:

select
  Modelo,
  case when January Is not null then January else 0 end as Enero,
  case when February Is not null then February else 0 end as Febrero,
  case when March Is not null then March else 0 end as Marzo,
  case when April Is not null then April else 0 end as Abril,
  case when May Is not null then May else 0 end as Mayo,
  case when June Is not null then June else 0 end as Junio,
  case when July Is not null then July else 0 end as Julio,
  case when August Is not null then August else 0 end as Agosto,
  case when September Is not null then September else 0 end   as Setiembre,
  case when October Is not null then October else 0 end   as Octubre,
  case when November Is not null then November else 0 end   as Noviembre,
  case when December Is not null then December else 0 end   as Diciembre
 from
 (
select  v.tyt01_nombre as Modelo,
datename(month,c.tyt15_fecha_cotizacion) as Mes
,COUNT(*) as Total
from  tyt15_cotizaciones c  inner join tyt01_vehiculos v on c.tyt01_id = v.tyt01_id
where c.tyt15_fecha_cotizacion between '2016-01-01 00:00:00' and '2016-12-31 23:59:59'
group by v.tyt01_nombre,
datename(month,tyt15_fecha_cotizacion)
) T
PIVOT (SUM(T.Total) FOR T.Mes IN ([January],[February],[March]
,[April],[May],[June],[July],[August],[September],
[October],[November],[December]))PVT
go

The result is this Query Result

now I need to make a similar query but grouping by day,and that the result is something like this Result I need

I would greatly appreciate your help

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • will you be able to grouping per date like this https://stackoverflow.com/questions/30988419/group-by-date-without-time Or do you really have a very bad db design? – zod Aug 25 '17 at 21:45
  • 1
    Possible duplicate of [Compute average sales per day in MySQL](https://stackoverflow.com/questions/34385870/compute-average-sales-per-day-in-mysql) – zod Aug 25 '17 at 21:52

0 Answers0