我尝试计算特定产品占产品总数量的百分比。我写了一个运行良好的 SQL 查询。但是当我尝试用 Query DSL 编写时,我遇到了一个问题,我真的很难编写这种查询。
SELECT ROUND((c.v2/f.v1)*100,2) , MONTH AS RESULTt
FROM
(SELECT SUM(Quantite)as v1,MONTH FROM Total_sold_view WHERE id_company='379' AND
year=2009 GROUP BY MONTH ORDER BY MONTH ASC) f,
(SELECT Quantite as v2,MONTH FROM Total_sold_view WHERE id_company='379' AND year=2009
AND product_type=13 ORDER BY MONTH ASC) c
WHERE c.MONTH=f.MONTH