SELECT priceEach,
CASE WHEN SUM((priceEach/(priceEach) * 100) BETWEEN 19 AND 20 THEN 'yes' ELSE NULL hm
FROM orderdetails
WHERE hm = 'yes'
ORDER BY priceEach DESC;
这会有用吗?
我想不出如何找到对总体贡献20%的价格部分
答案 0 :(得分:0)
这个答案完全基于我对这个问题的理解。不确定您是否正在寻找此结果。请试试这个:
SELECT priceEach,
CASE WHEN SUM((priceEach/(priceEach) * 100) BETWEEN 19 AND 20 THEN 'yes' ELSE NULL END hm
FROM orderdetails
ORDER BY priceEach DESC
having Count(CASE WHEN SUM((priceEach/(priceEach) * 100) BETWEEN 19 AND 20 THEN 1 ELSE 0 end) = 1;
答案 1 :(得分:0)
没有!!!你应该有
1. group by
on priceEach
喜欢这个群组(priceEach)
2. end
像这样的案例
CASE WHEN SUM((priceEach/(priceEach) * 100) BETWEEN 19 AND 20 THEN 'yes' ELSE NULL end
你选择将是这样的
SELECT priceEach,
CASE WHEN SUM((priceEach/(priceEach) * 100) BETWEEN 19 AND 20 THEN 'yes' ELSE NULL end hm
FROM orderdetails
WHERE hm = 'yes'
group by priceEach
ORDER BY priceEach DESC;
答案 2 :(得分:0)
检查出来: - 我希望这就是你想要的。有点冗长,但值得努力。
RUN
答案 3 :(得分:0)
在MySQL中,您可以使用变量执行此操作:
select od.*
from (select od.*, (@rn := @rn + 1) as rn
from orderdetails od cross join (select @rn := 0) params
where hm = 'yes'
order by price desc
) od
where floor(rn / 0.2) = @rn;