Вы подсчитываете строки ежедневных агрегатов.
Чтобы суммировать предварительно агрегированные счета, вам теперь нужно суммировать столбец count (см. type
)
{
"queryType" : "groupBy",
"dataSource" : "ERS_DAILY",
"granularity" : "all",
"intervals" : [ "2018-07-12T00:00:00.000Z/2018-07-13T00:00:00.000Z" ],
"descending" : "false",
"aggregations" : [ {
"type" : "longSum",
"name" : "COUNT",
"fieldName" : "COUNT"
} ],
"postAggregations" : [ ],
"dimensions" : [ "event_id" ]
}
Попробуйте это
(select products.*,
sum(100000) as count1,
product_sku.price AS sku_price,
product_sku.label AS sku_label
from `products`
left join `product_sku` on `products`.`id` = product_sku.product_id
AND product_sku.is_primary = "Yes" AND products.is_variation = "Yes"
where `product_name` = "testproduct1" and `status` = "Active"
and exists (select * from `campaign` where `products`.`exclusive_for` = `campaign`.`id` and `status` = "Published" and `active_inactive` = "Active" or `products`.`exclusive_for` is null) group by `products`.`id` having id != 0)
union
(select * from
(select products.*,
ROUND ( (LENGTH(products.product_name)- LENGTH( REPLACE ( products.product_name, "testproduct1", "") ) ) / LENGTH("testproduct1") ) AS count1,
product_sku.price AS sku_price,
product_sku.label AS sku_label
from `products`
left join `product_sku` on `products`.`id` = product_sku.product_id
AND product_sku.is_primary = "Yes" AND products.is_variation = "Yes"
where (`products`.`product_name` LIKE "%testproduct1%" or `products`.`description` LIKE "%testproduct1%") and `status` = "Active"
and exists (select * from `campaign` where `products`.`exclusive_for` = `campaign`.`id` and `status` = "Published" and `active_inactive` = "Active" or `products`.`exclusive_for` is null) having id != 0 )A
group by A.`p_id`)