我想创建一个列表,显示每个食品的总量。我已经获得了想要的数据,但是,它在分组依据所包含的成分列中显示了多个具有相同值的单元格。
我已经尝试重建脚本,但是我已经尽力了。
SELECT "recipeingredients"."ingredient",
("recipeingredients"."amountperservekg" * SUM("transactionGC"."Unit_Qty_Sold")) as "Total Ingredient"
FROM public.recipemain
left join "recipelinkingpos" on "recipemain"."recipename" = "recipelinkingpos"."sendrecipe"
left join "recipeingredients" on "recipemain"."recipeid" = "recipeingredients"."recipeid"
left join "transactionGC" on "recipelinkingpos"."Product_Name" = "transactionGC"."Product_Name"
where
ingredient is not null
and
date_trunc('week',"transactionGC"."Date/Time")
between (now()- interval '8 days') and (now()-interval '1 days')
group by
"recipeingredients"."amountperservekg",
"recipeingredients"."ingredient"
order by "recipeingredients"."ingredient" asc;
上述脚本的结果。我只希望每种成分只有一个实例。
Agar Agar 0.00018750000890577212
Almond, Slivered 0.021875000093132257
Anchovies 0.14999999664723873
Avocado 2.8500000424683094
Bacon 1.529999965801835
Bacon 4.139999907463789
Banana 0.11999999731779099
Barramundi 2.1600000858306885
Basil, Fresh 1.5199999660253525
Basil, Fresh 0.04800000227987766
Basil, Fresh 0.1599999964237213
Basil, Fresh 0.44999998807907104
Bay Leaves 0.005500000261235982
Bean Shoots 0.6000000089406967
Bean Shoots 0.3799999915063381
Beans, Green 2.1599999517202377
Beef, Rib Eye 5.200000077486038
Beef, Rump End 1.4000000208616257
Beef, Striploin 0.35999999195337296
Beef, Striploin 3.0000001192092896