× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 21-Jul-2015 16:15 -0600, Hoteltravelfundotcom wrote:
I want to use MAX in this SQL. Because we have some cases where
Duplicates are entered. IN this particular sales data, there is no
check in the application.

So I have a reporting tool using a view and would need to remove
these dupes. The dupes will be manifest in these 5 fields and the
time is the only one that will differ (possibly the date)

Using a report\query to correct errors in the row-data is a fool's errand. Fix the application(s) and the data, then just compose the proper queries\reports, rather than attempt to use any /tricks/ to make the improper data appear correct [merely] in presentation.

so If I select on MAX I would get a distinct: So far it is not
allowing, it gives an error:

"SQL0122 - Column OHPTTC or expression in SELECT list not valid."
The dupes appear here: an example: We want only the 001 row but only
1 of the next 2

---------------------------------
OTORD# OTUSRN OTTRNC OTTRND OTTRT

05648230 MMOLINA 001 20,150,610 105,428
05648230 MMOLINA RRF 20,150,610 113,127
05648230 MMOLINA RRF 20,150,610 105,443

SELECT max(T01.OTORD#), max(T01.OTUSRN)
, max(T01.OTTRNC), max(T01.OTTRND)
, max(T01.OTTRT ), T01.OHPTTC
, T01.OHSLR#, T01.OHORDT
, T01.OHORDD, T01.OHTTN$
, T02.RFCAT, T02.RFSLC
, T02.RFSQ2, T02.RFDTA
FROM SLSDTA.CLSPAYT22 T01
INNER JOIN REPDTA.REFERRF T02
ON T01.OTTRNC = T02.RFSLC
WHERE RFCAT = '5058'
AND RFSQ2 = '1'


From the given description, I infer the desired\expressed obfuscation would be effected using the following query, albeit with the maximum values coming from any of the so-called /duplicate/ rows rather than all values coming from any one [the same] particular row; note the MAX() is on each column *besides* the first three which are used to group:

SELECT T01.*
, T02.RFCAT, T02.RFSLC
, T02.RFSQ2, T02.RFDTA
FROM ( SELECT OTORD#, OTUSRN, OTTRNC
, max(T01.OTTRND) as OTTRND
, max(T01.OTTRT ) as OTTRT
, max(T01.OHPTTC) as OHPTTC
, max(T01.OHSLR#) as OHSLR#
, max(T01.OHORDT) as OHORDT
, max(T01.OHORDD) as OHORDD
, max(T01.OHTTN$) as OHTTN$
FROM SLSDTA.CLSPAYT22
GROUP BY
OTORD#, OTUSRN, OTTRNC
) T01
INNER JOIN REPDTA.REFERRF T02
ON T01.OTTRNC = T02.RFSLC
WHERE RFCAT = '5058'
AND RFSQ2 = '1'


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.