user1820913
user1820913

Reputation: 1

using case when then

I have the following snippet:

COUNT (DISTINCT CASE WHEN (a.FIRST_ORDER_DAY = b.ORDER_DAY) THEN a.CUSTOMER_ID END) AS new_customer

I want to replicate the exact same behavior as a select function instead of a count function. As I don't know the function well enough, I don't know how:

i.e. beforehand the result was "x new customers"

Now I want to have a result, which would be

new customers:
123 (customer ID)
234 (another customer iD)

and so on.

I would appreciate your help!

Upvotes: 0

Views: 85

Answers (1)

MatBailie
MatBailie

Reputation: 86706

From what I understand, you just want a list of the customer IDs that are new.

For that, you don't need a CASE statement at all...

SELECT DISTINCT
  a.CustomerID
FROM
  ???
WHERE
  a.FIRST_ORDER_DAY = b.ORDER_DAY

??? should be replaced with whatever joins you have (but didn't include in your question).

Upvotes: 2

Related Questions