SQL Query: COUNT value in Column, ignoring Group By - Found solutions not supported in Zoho

SQL Query: COUNT value in Column, ignoring Group By - Found solutions not supported in Zoho

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:
  1.           
  2. SELECT DISTINCT
  3. "Order",
  4. "SKU",
  5. GROUP_LAST("Other info"),
  6. GROUP_First ("Other info 2"),
  7.  COUNT("Order") AS "Count"
  8. FROM  "Orders" 
  9. GROUP BY
  10.  "Order",
  11.  "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
  1. SELECT
  2.  "Order",
  3.  COUNT("Order") AS "Count"
  4. 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:
  1. SELECT DISTINCT
  2.  "Order",
  3.  "SKU",
  4.  GROUP_LAST("Other info"),
  5. GROUP_First ("Other info 2"),
  6.  (
  7. SELECT
  8.  "Order",
  9.  COUNT("Order") AS "Count"
  10. FROM  "Orders" AS tab2 Where tab1."Order"=tab2."Order") A "Count"
  11. FROM  "Orders" AS tab1
  12. GROUP BY
  13.  "Order",
  14.   "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

      • Sticky Posts

      • Announcing Zoho Analytics 6.0 Beta!

        We are delighted to open up the next major version, Zoho Analytics 6.0 Beta! The new version comes packed with a wide range of functionalities for all persona, namely business users, data analysts, data engineers, and data scientists. Zoho Analytics team
      • What's New in Zoho Analytics - August 2024

        Hello Users! We are back with the latest updates and enhancements made to Zoho Analytics. Keep reading to learn more about them. Connect to the data hosted in the cloud without allow-listing the IP addresses Utilize Zoho Databridge to connect to the data
      • We are coming to your city! Zoho Analytics Community Meetup

        Hello, business leaders and data enthusiasts! We are delighted to announce that registrations are now open for the ZUG meetups, and we can't wait for you to be a part of them. Our in-house analytics experts are geared up to lead discussions on constructing
      • Zoho Analytics: 2021 Look Back

        As we start a new year in 2022, here's some of our top moments from 2021. Zoho Analytics in 2021
      • [Customer Talk] PREMO Group's Analyst Interview at Zoho Day 2022

        Premo Group, a 50 year old Spanish Manufacturing Company, has been our long-standing customer with #ZohoAnalytics. They've been using our platform for their end-to-end, unified business analytics solution.  Hear more from Claudio Cabeza, Director at PREMO