моя таблица ПРОДАЖ
ID | NAMEPRODUCT | CATEGORY | AMOUNT
1 | COMPUTER | IT | 600
2 | T-SHIRT | CLOTHING | 25
3 | Doll | TOY | 10
4 | KEYBORD | IT | 30
5 | CAP | CLOTHING | 10
3 | TOY CAR | TOY | 40
Я хотел бы сделать этот тип запроса:
SELECT SALES1.NAMEPRODUCT,
SALES1.CATEGORY,
SUM(SALES1.AMOUNT)/( select SUM(AMOUNT) FROM SALES AS SALES2 WHERE SALES1.CATEGORY=SALES2.CATEGORY) as ratio
from SALES AS SALES1
GROUP BY
SALES1.NAMEPRODUCT,SALES1.CATEGORY
NAMEPRODUCT | CATEGORY | ratio
COMPUTER | IT | 0,95
T-SHIRT | CLOTHING | 0,71
Doll | TOY | 0,20
KEYBORD | IT | 0,5
CAP | CLOTHING | 0,29
TOY CAR | TOY | 0,80
ИЛИ
SELECT SALES1.NAMEPRODUCT,
SALES1.CATEGORY,
SUM(SALES1.AMOUNT),
( select SUM(SALES2 .AMOUNT) FROM SALES2 WHERE SALES1.CATEGORY=SALES2.CATEGORY) AS TOTAL_AMOUNT_for_category
from SALES1
GROUP BY
SALES1.NAMEPRODUCT,
SALES1.CATEGORY
NAMEPRODUCT | CATEGORY | AMOUNT |TOTAL_AMOUNT_for_category
COMPUTER | IT | 600 | 630
T-SHIRT | CLOTHING | 25 | 35
Doll | TOY | 10 | 50
KEYBORD | IT | 30 | 630
CAP | CLOTHING | 10 | 35
TOY CAR | TOY | 40 | 50
Я использую базу данных Cassandra с Apache Соединитель улья. Я не могу сделать запрос такого типа с ульями и кассандрой. Может ли кто-нибудь мне помочь?