473,403 Members | 2,293 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,403 software developers and data experts.

unique values combined with COUNT()

4
Hi there,

The following statement produces multiple results, but I only need one.

SELECT CREDITOR_NAME, CREDITOR_NO, INV_ID, TRAIN_COUNT, COUNT(CREDITOR_NO) as number_of_inv
FROM DIPPMX.ADMIN.TI$ST_RECO
GROUP BY CREDITOR_NAME, INV_ID, TRAIN_COUNT, CREDITOR_NO
HAVING COUNT(CREDITOR_NO) >= 5

Normally I would include the CREDITOR_NAME in MIN(), but this wont work due to the COUNT(CREDITOR_NO). Any help is appreciated.

Thanks in advance,
Alain
Aug 28 '08 #1
3 1306
code green
1,726 Expert 1GB
You probably need a WHERE condition to filter your result.
You haven't explained which one result you need and why, but you could use TOP.
Aug 28 '08 #2
preek
4
I have found my solution; I actually did use MIN() as suggested:

SELECT CREDITOR_NAME, CREDITOR_NO, MIN(INV_ID), COUNT(CREDITOR_NO) as no_of_inv
FROM DIPPMX.ADMIN.TI$ST_RECO
GROUP BY CREDITOR_NAME, CREDITOR_NO
HAVING COUNT(CREDITOR_NO) >= 3
Aug 28 '08 #3
code green
1,726 Expert 1GB
OK. Well done.
So you needed the lowest INV_ID number. This is generally the oldest.
I have to admit I cannot see what you are trying to do.
It helps future posters who may have a similar problem if you explain why you need such a specific result
Aug 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: kevin parks | last post by:
hi. I've been banging my head against this one a while and have asked around, and i am throwing this one out there in the hopes that some one can shed some light on what has turned out to be a...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
2
by: Jo Goos | last post by:
Hello, I would like to count the unique values of a specific element in an XPath statement. Let's say I have the next XML document ... <CLUB> <MEMBER> <NAME>Fred</NAME>...
6
by: Poul Møller Hansen | last post by:
I have made a stored procedure, containing this part for generating a unique reference number. SET i = 0; REPEAT SET i = i + 1; SELECT RAND() INTO reference FROM SYSIBM.SYSDUMMY1; SET...
2
by: SJM | last post by:
I have a report that displays records of real estate properties. It is possible for each property to appear a number of times for various reasons. Each record however is unique. What I would like...
2
by: rcamarda | last post by:
I've been trying to solve this problem for better of 4 days: We summarize registrations of students on a daily basis, however they are net changes. Example: A student registers one class for...
1
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
1
by: muld | last post by:
I've inherited a database system designed to calculate sickness absence statistics. There is a main table with an employee ID which also holds the number of days worked by that person in a year ....
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.