select s.product, s.category, 1 as qty
from sales s join
numbers n
on n.n <= s.qty and n.n > 0;
在mysql中,可以使用变量生成这样的表。例如,如果 sales 足够大:
select s.product, s.category, 1 as qty
from sales s join
(select (@rn := @rn + 1) as n
from sales s cross join
(select @rn := 0) params
) n
on n.n <= s.qty and n.n > 0;
select category,main1.product,main2.qty from (select category,product,
split(substring(repeat(concat(1,','),int(qty)),0,int(qty*2)-1),",") as qty from
(select collect_set(product) product,category,
sum(qty) qty
from sales) main
lateral view explode(product) main1 as product
lateral view explode(qty) main2 AS qty;
3条答案
按热度按时间oknrviil1#
如果您有一个数字表,您可以:
在mysql中,可以使用变量生成这样的表。例如,如果
sales
足够大:wkftcu5l2#
Hive
ovfsdjhp3#
我自己想办法回答(这是在Hive里)