Hey everyone,
I have the following database
Order # | SKU | Other info | Other info2 - always first when grouped
1 SKU1 Name |abc
1 SKU1 Name |xyz
1 SKU2 Name |xyz
1 SKU2 Name |xyz
2 SKU 2 Name |abc
2 SKU 2 Name |xyz
3 SKU3 Name |xyz
3 SKU3 Name |abc
4 SKU1 Name |xyz
4 SKU1 Name |abc
4 SKU3 Name |xyz
4 SKU3 Name |abc
... ... ...
With a total of 25.000 lines.
I need to get the following:
- Get rid of the duplicates, every line is at least double in there
- Count how many rows exist with the specific Order #
- Get all columns
- From the "Other infos 2" column I always need the first value (when grouped)
So I need a final solution that looks like that:
Order # | SKU | Other info | Count | Other info2
1 SKU1 Name 2 |abc
1 SKU2 Name 2 |xyz
2 SKU 2 Name 1 |abc
3 SKU3 Name 1 |xyz
4 SKU1 Name 2 |xyz
4 SKU3 Name 2 |xyz
... ... ...
So far, I get everything, except the counting correct:
-
- SELECT DISTINCT
- "Order",
- "SKU",
- GROUP_LAST("Other info"),
- GROUP_First ("Other info 2"),
- COUNT("Order") AS "Count"
- FROM "Orders"
- GROUP BY
- "Order",
- "SKU"
The problem is, that it now counts only the number of orders within the Group Order, SKU - it looks like this:
Order # | SKU | Other info | Count | Other info2
1 SKU1 Name 1 |abc
1 SKU2 Name 1 |xyz
2 SKU 2 Name 1 |abc
3 SKU3 Name 1 |xyz
4 SKU1 Name 1 |xyz
4 SKU3 Name 1 |xyz
... ... ...
What I already tried:
- I made another query table, with
- SELECT
- "Order",
- COUNT("Order") AS "Count"
- FROM "Orders"
To get the right count value, and than join it with the other table. The problem is that Zoho Reports does not allow that, because with 2x 25.000 lines it would take to long.
So I tried to have a subquery within the first query:
- SELECT DISTINCT
- "Order",
- "SKU",
- GROUP_LAST("Other info"),
- GROUP_First ("Other info 2"),
- (
- SELECT
- "Order",
- COUNT("Order") AS "Count"
- FROM "Orders" AS tab2 Where tab1."Order"=tab2."Order") A "Count"
- FROM "Orders" AS tab1
- GROUP BY
- "Order",
- "SKU"
Here everything worked fine, as long as I keep the WHERE out if it. I than read that Zoho is not expecting related subqueries, so this solution is also not working.
In a third step, I tried to change the source table "Orders", by adding another row with an aggregate form column, but apparently Zoho Reports does not allow columns with aggregation formulas in it.
So I really need help here, I tried 3 solutions that are all blocked by the Zoho Report limitations. Unfortunately, I also need the group function to get only the first row of "Other info 2".
Thanks and best,
Fabian
Edited to make it a little bit clearer