我对SQL& Apex,但我需要一个声明,我真的很感谢你对此的帮助。 Apex饼图的语法是:
SELECT link, label, value
我的表看起来像这些简单的草图:
+------+-----------+---------+
| ID | Company | Item |
+------+-----------+---------+
| 1 | AAA |Some |
| 2 | BB |Stuff |
| 3 | BB |Not |
| 4 | CCCC |Important|
| 5 | AAA |For |
| 6 | DDDDD |Question?|
+------+-----------+---------+
我想显示公司的百分比。
问题:所有少于5件商品的公司应该合并为一个“其他”列。对我来说,困难在于将“不重要”的公司结合起来。
到目前为止,我的发言如下:
SELECT null link,
company label,
COUNT(ID) value FROM table HAVING COUNT(ID) > 5 GROUP BY company
这是一个精彩的图表草图。 :D
感谢您的想法!
答案 0 :(得分:1)
我没有让SQL Developer出现在我面前,但是这个(或者一个接近的变体)应该适合你:
WITH company_count
AS (
SELECT CASE
WHEN count(*) < 5
THEN 'Other'
ELSE company
END AS company_name,
id
FROM tablename
),
company_group
AS (
SELECT company_name,
count(id) item_count
FROM company_count
GROUP BY company_name
)
SELECT NULL AS link,
company_name AS label,
item_count AS value
FROM company_group;
希望它有所帮助!
答案 1 :(得分:0)
好的伙计们,我找到了用例的答案。它与Ollies的回答非常相似。再次感谢您的帮助!
WITH sq1 AS (SELECT company, COUNT (*) AS count FROM
(SELECT CASE WHEN COUNT (*) OVER (Partition By company) > 5 THEN company
ELSE 'other' END AS company, id FROM table) GROUP BY company)
SELECT null link, company label, count value FROM sq1 ORDER BY count desc