[英]How to get COUNT of records return by measures in JSON query of CubeJS
I want to get a count of records return by the below JSON query of CubeJS.我想通过以下 CubeJS 的 JSON 查询获取返回的记录数。
{
"measures": [
"Employee.salaryTotal"
],
"timeDimensions": [
{
"dimension": "Employee.createdat"
}
],
"dimensions": [
"Employee.isactive"
],
"filters": []
}
This JSON query generates below SQL in CubeJS:此 JSON 查询在 CubeJS 中生成以下 SQL:
SELECT
`employee`.`isActive` `employee__isactive`,
SUM(salary) `employee__salary_total`
FROM
DEMO.Employee AS `employee`
GROUP BY
1
ORDER BY
2 DESC
LIMIT
10000
Output of SQL is: SQL的输出是:
+---------------------+------------------------+
| employee__isactive | employee__salary_total |
+---------------------+------------------------+
| Y | 17451 |
| N | 1249 |
+---------------------+------------------------+
But what if I want count of records return by above SQL.但是如果我想通过上面的 SQL 返回记录计数怎么办。
example:例子:
SELECT COUNT(*) FROM
(SELECT
`employee`.`isActive` `employee__isactive`,
SUM(salary) `employee__salary_total`
FROM
DEMO.Employee AS `employee`
GROUP BY
1
ORDER BY
2 DESC
LIMIT
10000) AS EMPSAL
Expected result should be like this:预期结果应该是这样的:
+------------+
| # COUNT(*) |
+------------+
| 2 |
+------------+
Currently there's no way to perform COUNT
operation on top of final Cube.js query.目前无法在最终的 Cube.js 查询之上执行
COUNT
操作。 If you're trying to implement paging functionality you can use offset
and limit
query parameters to check if there's a next page available by means of limit
and row count comparison: https://cube.dev/docs/query-format#query-properties .如果您尝试实现分页功能,您可以使用
offset
和limit
查询参数通过limit
和行数比较来检查是否有下一页可用: https : //cube.dev/docs/query-format#query-属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.