我有一个查询,我有问题,我想 找到不同 Leaf_category_id所以我想分组操作。
如何修改此查询以替换具有的位置。并且按操作分组不为空
select Leaf_Category_id,totalOrders,totalCartAdditions,clicks,clicks * 100/ t.s as `click_percent`
from leafCategoryAnalysis
CROSS JOIN (SELECT SUM(clicks) AS s FROM leafCategoryAnalysis) t
where Leaf_Category_id is not NULL
order by clicks
答案 0 :(得分:1)
select Leaf_Category_id,sum(totalOrders),sum(totalCartAdditions),sum(clicks),sum(clicks) * 100/ sum(t.s) as `click_percent`
from leafCategoryAnalysis
CROSS JOIN (SELECT SUM(clicks) AS s FROM leafCategoryAnalysis) t
where Leaf_Category_id is not NULL
group by Leaf_Category_id
试试这个。我没有试过自己。希望能帮助到你。 我只是在其他列上应用了sum函数。