473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

For SQL Buffs

Hi,

I have MyTable (ID, BUSINESS_UNIT_ID, CUSTOMER_NUMBER). I need a list
of customer numbers that exist in more than one BUSINESS_UNIT_ID.

Thanks!

Sep 14 '06 #1
3 1222
SELECT CUSTOMER_NUMBER
FROM MyTable
GROUP BY CUSTOMER_NUMBER
HAVING COUNT(DISTINCT BUSINESS_UNIT_ID)>1

Sep 14 '06 #2
Awesomeness.

Didn't know you could throw that DISTINCT in there like that.

Sep 14 '06 #3
> I have MyTable (ID, BUSINESS_UNIT_ID, CUSTOMER_NUMBER). <<

Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.

My guess is that "id" is a totally redundant, non-relational rowing
numbers that newbies who never read anything on RDBMS use. Did you
mean

CREATE TABLE CustomerAssignments
(business_unit INTEGER NOT NULL
REFERENCES OrgChart(business_unit_id)
ON UPDATE CASCADE,
customer_id NTEGER NOT NULL
REFERENCES Customers (customer_id)
ON UPDATE CASCADE
ON DELETE CASCADE ,
PRIMARY KEY (business_unit_id, customer_id));
> I need a list of customer numbers that exist in more than one BUSINESS_UNIT_ID.<<
SELECT customer_id
FROM CustomerAssignments
GROUP BY customer_id
HAVING COUNT(*) 1;

Without the key, you would have to use COUNT(DISTINCT business_unit_id)

Sep 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Frank Rizzo | last post by:
Hello, I have an OCX control on my WinForm (don't ask, i have to use it) and it generally works well. One of the methods of the OCX prints to an hDC (device context handle for history buffs). ...
6
by: Lucvdv | last post by:
In a sorted list, certain characters are grouped together, for example "çb" (cedille b) comes after "ca" but before "cc". Is there a built-in way to find out what 'base character', such as C for...
13
by: Web Developer | last post by:
I'm trying to understand how async callbacks are possible with web services since they use HTTP (which is stateless) for their communication protocol. What happens under the covers to allow...
21
by: Viken Karaguesian | last post by:
Hello all, I'm having a weird design issue with IE. The bottom borders on two of my div's stop 1px or 2px short of the right side of the div. In Mozzilla and Opera, these borders go completely...
6
by: c00i90wn | last post by:
Hey, I'm having a problem with the xml.dom.minidom package, I want to generate a simple xml for storing configuration variables, for that purpose I've written the following code, but before pasting...
4
by: Christopher Granade | last post by:
I don't know if this is the right place to submit this or not, but I had a rough idea for a new web standard that would work closely with XML that I wanted to submit to the community for...
4
by: Stu | last post by:
Can somebody give me a scanf statment that will parse out the value between the pipe signs but not including the the pipe signs. @xxx:|this value| Thanks to all that answer this post.
1
by: Erik Lautier | last post by:
Hello, I'm using a multipart/form-data upload to put an image into SQL Server, and it appears to be working, but I'm unable to display the image. All I'm getting is the text of the URL we're on in...
8
by: coder_lol | last post by:
I put together a quick array template for MS Visual Studio 2003, but I ran into some trouble. It's been quite a while since I had to roll my own templates, so I'd appreciate all help. Example 1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.