如何比较postresql和上周在同一个查询中的产品值的总和?举个例子,第一列显示J天所有奶昔的和,然后是j-7,第三列是显示演化?

发布于 2022-02-25 10:40:20
我这样做是用连接SQL查询的
Select a.restaurant, a.nb_milkshake_J, b.nb_milkshake_J_7,
(((a.nb_milkshake_J - b.nb_milkshake_J_7)/b.nb_milkshake_J_7)*100)
from
(select restaurant,cast(sum(quantite) as float) as nb_milkshake_J
from public.ventes_restaurant
where produit_groupe like 'MILKSHAKES'
and produit like 'MILKSHAKES%'
and date_commande ='2021/11/26'
group by restaurant,date_commande
) a full join
(select restaurant,cast(sum(quantite) as float) as nb_milkshake_J_7
from public.ventes_restaurant
where produit_groupe like 'MILKSHAKES'
and produit like 'MILKSHAKES%'
and date_commande ='2021/11/19'
group by restaurant,date_commande) b on a.restaurant = b.restauranthttps://stackoverflow.com/questions/71255536
复制相似问题