--查询最畅销的三种花(名称,价格)
--查询本月的销售信息(名称,数量,总金额)
--查询每种花的总销售量(名称,销售量)
https://zhidao.baidu.com/question/925068243900282539.html
--查村所有花的信息
select * from T_Flower
--查询价格最高的花(名称,价格)
select top 1 FlowerName '名称',FlowerPrice '价格' from T_Flower order by FlowerPrice desc
--添加一种新的花,(名称:蓝色妖姬,价格:300)
insert into T_Flower values('蓝色妖姬',300)
--将“玫瑰"花的价格修改为150元
update T_Flower set FlowerPrice=150 where FlowerName='玫瑰'
--查询最畅销的三种花(名称,价格)
select top 3 b.FlowerName '名称',b.FlowerPrice '价格' from T_Expense a
inner join T_Flower b on a.FlowerId = b.FlowerId
group by b.FlowerName,b.FlowerPrice
order by sum(a.Num) desc
--查询本月的销售信息(名称,数量,总金额)
select b.FlowerName '名称',b.FlowerPrice '数量',(sum(Num)*b.FlowerPrice) '总金额' from T_Expense a
inner join T_Flower b on a.FlowerId = b.FlowerId
WHERE datediff(month,ExpenseDate,getdate())=0
group by b.FlowerName,b.FlowerPrice
order by sum(a.Num) desc
--查询每种花的总销售量(名称,销售量)
select b.FlowerName '名称',sum(a.Num) '销售量' from T_Expense a
inner join T_Flower b on a.FlowerId = b.FlowerId
group by a.FlowerId, b.FlowerName