You are on page 1of 1

create view a

as
select sum(b.boltotal) as total, MONTH(b.bolfecha) as mes from tbboleta as b
where YEAR(b.bolfecha) = '2007'
group by month(b.bolfecha)
go

go
create view b
as
select sum(db.cantidad) as cantidad, MONTH(b.bolfecha) as mes from tbboleta as b
inner join tbdetboleta as db on b.bolnumero=db.bolnumero
where YEAR(b.bolfecha) = '2007'
group by month(b.bolfecha)
go

create view c
as
select t1.bolnumero as numero,MONTH(t1.bolfecha) as mes ,t1.boltotal as total from
tbboleta as t1,(
select MONTH(A.bolfecha) as mes, max(A.boltotal) as total from tbboleta A
where YEAR(A.bolfecha) = '2007'
group by MONTH(A.bolfecha)) as t2
where MONTH(t1.bolfecha)=t2.mes and t1.boltotal=t2.total and
year(t1.bolfecha)='2007'

go

select case a.mes


when 1 then 'Enero'
when 2 then 'Febrero'
when 3 then 'Marzo'
when 4 then 'Abril'
when 5 then 'Mayo'
when 6 then 'Junio'
when 7 then 'Julio'
when 8 then 'Agosto'
when 9 then 'Septiembre'
when 10 then 'Octubre'
when 11 then 'Noviembre'
when 12 then 'Diciembre'
end as Mes,a.total as 'Monto total de las boletas',b.cantidad as 'Cantidad total de
suministros',c.numero as 'Boleta con mayor venta' from a
inner join b on a.mes = b.mes
inner join c on a.mes = c.mes
order by a.mes
go

You might also like