473,574 Members | 2,288 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"HAVING" problems with query and using 'having' with group by

Hi,
I am trying to write a query in Oracle which I have not done before,
and are having some difficulty getting my result.

Please check my query and my results.

select max(note.dateti me),
acgr.group_code ,
bank.local_acc_ no,
bank.short_name ,
DECODE
(bank.account_t ype,
0,'Nostro',
1,'Internal',
2,'Safe Keeping',
3,'Draft',
4,'Vostro',
5,'Suspense',
6,'Exchange',
7,'Netting',
8,'Mutual Funds',
'UNKNOWN') AS "Acc Type",
item.gin,
item.value_date ,
item.entry_date ,
item.ls_type AS "LS Type",
item.currency AS "Currency",
item.amount AS "Amount",
item.sfield_7 AS "SField 7",
item.sfield_8 AS "SField 8",
item.sfield_9 AS "SField 9",
item.bran_code,
note.notetext
FROM
grup,
acgr,
bank,
item,
note
WHERE grup.group_code = acgr.group_code
AND acgr.corr_acc_n o = bank.corr_acc_n o
AND bank.corr_acc_n o = item.corr_acc_n o
AND item.corr_acc_n o = note.corr_acc_n o
AND item.gin = note.gin
AND item.flag_2 = 0
AND grup.group_code = 'GMSAZSGREC99'
and bank.account_ty pe in (0)
group by acgr.group_code ,
bank.local_acc_ no,
bank.short_name ,
bank.account_ty pe,
item.gin,
item.value_date ,
item.entry_date ,
item.ls_type,
item.currency,
item.amount,
item.sfield_7,
item.sfield_8,
item.sfield_9,
item.bran_code,
note.notetext
a subset of the Results (I have taken some colums out to make it a
little
easier to read)

DATETIME Group Code Local A/c Num GIN Amount Bran Code NOTETEXT
16/10/2003 2:04:39 GMSAZSGREC99 26001777 2518 2140.4 AUSREG >> Source
Code was AUSRE
17/10/2003 6:06:34 GMSAZSGREC99 26001777 2518 2140.4 AUSREG Paul
chasing up with client
24/10/2003 0:28:33 GMSAZSGREC99 26001777 2554 3050000 AUSREG >> Source
Code was AUSRE
22/10/2003 1:33:34 GMSAZSGREC99 25299777 2708 279.96 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:09 GMSAZSGREC99 25299777 2708 279.96 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2708 279.96 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:34 GMSAZSGREC99 25299777 2710 312.88 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:09 GMSAZSGREC99 25299777 2710 312.88 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2710 312.88 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:34 GMSAZSGREC99 25299777 2712 347.56 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:09 GMSAZSGREC99 25299777 2712 347.56 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2712 347.56 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:34 GMSAZSGREC99 25299777 2714 353.18 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:08 GMSAZSGREC99 25299777 2714 353.18 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2714 353.18 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:34 GMSAZSGREC99 25299777 2716 762.56 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:08 GMSAZSGREC99 25299777 2716 762.56 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2716 762.56 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:34 GMSAZSGREC99 25299777 2718 858.21 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:08 GMSAZSGREC99 25299777 2718 858.21 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2718 858.21 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:33 GMSAZSGREC99 25299777 2720 869.82 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:08 GMSAZSGREC99 25299777 2720 869.82 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2720 869.82 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:33 GMSAZSGREC99 25299777 2722 1998.92 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:08 GMSAZSGREC99 25299777 2722 1998.92 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:31 GMSAZSGREC99 25299777 2722 1998.92 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:33 GMSAZSGREC99 25299777 2724 2405.15 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:08 GMSAZSGREC99 25299777 2724 2405.15 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:31 GMSAZSGREC99 25299777 2724 2405.15 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 1:33:33 GMSAZSGREC99 25299777 2726 3151.99 AUSRE >> Source
Code was AUSRE
24/10/2003 0:29:07 GMSAZSGREC99 25299777 2726 3151.99 AUSRE >> Source
Code was AUSREG
24/10/2003 0:29:31 GMSAZSGREC99 25299777 2726 3151.99 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 2:53:18 GMSAZSGREC99 25299777 2730 133.04 AUSTSG >> Source
Code was AUSRE
24/10/2003 3:02:37 GMSAZSGREC99 25299777 2750 261.29 AUSFU >> Source
Code was AUSRE
3/10/2003 7:04:21 GMSAZSGREC99 26001777 3920 512.86 AUSGV reg >>
Source Code was AUSRE
3/10/2003 7:04:35 GMSAZSGREC99 26001777 3920 512.86 AUSGV Wholeslae
registry to investigate and advise
8/10/2003 0:17:29 GMSAZSGREC99 26001777 3920 512.86 AUSGV W/reg to
transfer to Treasury Account
8/10/2003 6:35:48 GMSAZSGREC99 26001777 3920 512.86 AUSGV gv >> Source
Code was AUSREG
8/10/2003 6:36:26 GMSAZSGREC99 26001777 3920 512.86 AUSGV reg >>
Source Code was AUSGV
8/10/2003 6:36:49 GMSAZSGREC99 26001777 3920 512.86 AUSGV Wholesale
Registry investigating with GVC for reimbursement
14/10/2003 3:42:25 GMSAZSGREC99 26001777 3920 512.86 AUSGV Paul has
signed off to reimburse the portfolio >> Source Code was AUSREG
14/10/2003 3:42:28 GMSAZSGREC99 26001777 3920 512.86 AUSGV Paul has
signed off to reimburse the portfolio


What I want to achieve is all records with a maximum datetime for each
GIN showing the notetext details.

Example of what I want to achieve.

DATETIME Group Code Local A/c Num GIN Amount Bran Code NOTETEXT
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2708 279.96 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2710 312.88 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2712 347.56 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2714 353.18 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2716 762.56 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2718 858.21 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:32 GMSAZSGREC99 25299777 2720 869.82 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:31 GMSAZSGREC99 25299777 2722 1998.92 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:31 GMSAZSGREC99 25299777 2724 2405.15 AUSRE Email sent
to UTP to enter ledgers
24/10/2003 0:29:31 GMSAZSGREC99 25299777 2726 3151.99 AUSRE Email sent
to UTP to enter ledgers
22/10/2003 2:53:18 GMSAZSGREC99 25299777 2730 133.04 AUSTSG >> Source
Code was AUSRE
24/10/2003 3:02:37 GMSAZSGREC99 25299777 2750 261.29 AUSFU >> Source
Code was AUSRE
17/10/2003 6:06:34 GMSAZSGREC99 26001777 2518 2140.4 AUSREG Paul
chasing up with client
24/10/2003 0:28:33 GMSAZSGREC99 26001777 2554 3050000 AUSREG >> Source
Code was AUSRE
14/10/2003 3:42:28 GMSAZSGREC99 26001777 3920 512.86 AUSGV Paul has
signed off to reimburse the portfolio

I have got the above result by removing the notetext field from the
above query,
but I do require the field. I have also tried to use

having note.datetime = max(note.dateti me)

In the above query but the version of Oracle (which i don't what is)
gives me
ORA-00979: not a GROUP BY expression. Which I don't get in Sybase...?

Any help would be much appreciated.
Thanks
GM
Jul 19 '05 #1
1 5354

Try this:

select max(note.dateti me),

acgr.group_code ,

bank.local_acc_ no,

bank.short_name ,

DECODE

(bank.account_t ype,

,'Nostro',

1,'Internal',

2,'Safe Keeping',

3,'Draft',

4,'Vostro',

5,'Suspense',

6,'Exchange',

7,'Netting',

8,'Mutual Funds',

'UNKNOWN') AS "Acc Type",

item.gin,

item.value_date ,

item.entry_date ,

item.ls_type AS "LS Type",

item.currency AS "Currency",

item.amount AS "Amount",

item.sfield_7 AS "SField 7",

item.sfield_8 AS "SField 8",

item.sfield_9 AS "SField 9",

item.bran_code,

note.notetext

FROM

grup,

acgr,

bank,

item,

note

WHERE grup.group_code = acgr.group_code

AND acgr.corr_acc_n o = bank.corr_acc_n o

AND bank.corr_acc_n o = item.corr_acc_n o

AND item.corr_acc_n o = note.corr_acc_n o

AND item.gin = note.gin

AND item.flag_2 = 0

AND grup.group_code = 'GMSAZSGREC99'

and bank.account_ty pe in (0)

group by

acgr.group_code ,

bank.local_acc_ no,

bank.short_name ,

DECODE

(bank.account_t ype,

,'Nostro',

1,'Internal',

2,'Safe Keeping',

3,'Draft',

4,'Vostro',

5,'Suspense',

6,'Exchange',

7,'Netting',

8,'Mutual Funds',

'UNKNOWN') AS "Acc Type",

item.gin,

item.value_date ,

item.entry_date ,

item.ls_type,

item.currency,

item.amount,

item.sfield_7,

item.sfield_8,

item.sfield_9,

item.bran_code,

note.notetext;
--
Posted via http://dbforums.com
Jul 19 '05 #2

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

Similar topics

1
354
by: malcolm | last post by:
Hello, We have a small team building a project that involves some 30 or so c# assembly dlls. It is a client server application with 1 exe as the starting point. The dlls and exe are sharing an assemblyinfo file that has a strong name and version assiciated with it. We are having problems in the way we have been developing. We have made two...
14
1959
by: MLH | last post by:
I have the following code to list query names in Access 2.0's Immediate Window. Currently, it lists names of all saved queries. Can you suggest a modification that will result in it listing only names of queries referencing "tblCorrespondence"? Sub ListSavedQrys_Click () '****************************************************************** '...
2
2981
by: pierrelap | last post by:
Hello, I need to code a query that: 1-counts the number of time two companies have been in a deal together 2-in the five years that preceded the deal Lead Participant DealDate AAA BBB 01/01/1990 BBB AAA 01/01/1991 AAA BBB 01/01/1992 AAA BBB 01/01/1993 AAA BBB 01/01/1994
5
2947
by: a | last post by:
Is there a performance hit if I have many "using" statements that are unnecessary? For example: using System.Collections; when nowhere in my code I'm using System.Collections namespace. I'm really thinking about the default "using" statements put by VS.NET.
13
2047
by: Jacek Dziedzic | last post by:
Hi! <OT, background> I am in a situation where I use two compilers from different vendors to compile my program. It seems that recently, due to a misconfiguration, library conflict or my ignorance, with one of the compilers I am having trouble related to libuwind.so, which, to my knowledge, deals with the intricacies of unwinding the...
2
27681
by: whitsey | last post by:
Trying to concatenate two fields into one however I seem unable to do so. All I want is to execute the following SELECT MONTH(L.DATE) ||' '|| YEAR(L.DATE) as MTH_OF_YEAR FROM LOG L But I get this error:
3
5030
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, we've got a strange problem here: We've created an ASP.NET 2.0 web application using Membership.ValidateUser() to manually authenticate users with our website. The problem is: If the user has the "User must change password" flag set in Active Directory, ValidateUser() always returns false if that user wants to log in.
1
166
by: George | last post by:
Hi, I am trying to write a query in Oracle which I have not done before, and are having some difficulty getting my result. Please check my query and my results. select max(note.datetime), acgr.group_code, bank.local_acc_no, bank.short_name,
5
1873
by: Cirene | last post by:
I seem to remember seeing a solution where a databound dropdownlist (used as a FILTER for a gridview) had the 1st item as "ALL ITEMS". It used a query with a UNION. But I can't find the example. It used no code I believe. Anyone have this solution handy? Thanks!
0
7801
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8044
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8229
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7808
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8096
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3739
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3749
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1055
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.