If I understand correctly, he wants the Type / Code combination only once
and then the first customer no.
The following query should return this result:
Select Type, Code, Min(CustNo) CustNo
From YourTable
Group By Type, Code
Order By CustNo, Type, Code
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)
-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of John
Yeung
Sent: Samstag, 21. November 2020 00:03
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: Real life SQL Brain teaser
Choosing good example data is an art.
One thing that is confusing here is that it's not clear whether the
"Customer" and "combination" values are in the same space.
Let's say instead you have the following data:
Customer, Type, Code
100, T1, C1
100, T1, C2
200, T2, C3
200, T2, C4
300, T5, C1
400, T1, C1
400, T1, C2
Are the combinations still 1, 2, and 3? Or do they become 100, 200, and 300?
If the latter, does it matter whether you get 200, 300, 400 instead?
John Y.
On Wed, Nov 18, 2020 at 1:07 PM Dave <dfx1@xxxxxxxxxxxxxx> wrote:
In my table below there are 4 customers but only 3 distinct
combinations of Type and Code.
Customer Type Code
1 T1 C1
1 T1 C2
2 T2 C3
2 T2 C4
3 T5 C1
4 T1 C1
4 T1 C2
From this table, can I create the following table that contains each
combination of Type and Code only once ?
combination Type Code
1 T1 C1
1 T1 C2
2 T2 C3
2 T2 C4
3 T5 C1
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.