Question

Create HAVING clause and GROUP BY without it in SELECT clause

  • 16 January 2023
  • 0 replies
  • 13 views

Hi, 

Is there a way in LookML or within the Explore itself to replicate the following SQL query - where `order_id` and `customer_id` are dimensions?

The issue I’m having is I want to have `customer_id` in the GROUP BY clause but not in the SELECT clause, and I also want to have `order_id` in the HAVING clause. 

SELECT SUM(count_order_id) AS total_orders_made_by_same_customers
FROM (
SELECT
COUNT(order_id) AS count_order_id
FROM my_table
GROUP BY customer_id
HAVING COUNT(order_id) > 1
)

 


0 replies

Be the first to reply!

Reply