Decided to break my query in to bits, to help communicate what I am trying to achieve.
I have some information about a Customer and the Coupon Code they've used, in this format
| Customer | Coupon Code |
|---|---|
| 1 | FreeDel |
| 1 | FreeDel |
| 1 | FreeDel |
| 1 | 1562733 |
| 1 | 8842939 |
| 1 | 847hr64 |
| 1 | 83jd63j |
| 1 | FreeDel |
| 1 | 8eh33jr |
| 1 | AA-2637 |
| 1 | AA-9837 |
| 1 | Save200 |
| 1 | Save200 |
I want to sort it so that: If a known coupon-code prefix is available, then using syntax like this:
CASE WHEN Coupon Code LIKE 'AA-%' THEN 'AA-' CASE WHEN Coupon Code IS UNIQUE THEN 'UNIQUE' CASE WHEN Coupon Code IS NOT UNIQUE THEN 'NON-UNIQUE'
And so to output
| Count | Customer | Coupon Code Type |
|---|---|---|
| 6 | 1 | Non-Unique |
| 2 | 1 | AA- |
| 5 | 1 | Unique |
In this ideal, the known prefixes are added first as cases, and then unknown, unrepeated Coupon Codes are labelled Unique and then repeated Coupon Codes are labelled Non-Unique.
Any help would be super appreciated! :)
Table edits