473,748 Members | 11,134 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 5367

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 attempts at this. Attempt 1) In our first attempt, we basically had 1 folder that
14
1988
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 () '****************************************************************** ' Lists ALL the table names in the immediate window. ' ' This is useful code in many applications....
2
2990
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
2959
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
2063
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 stack upon an exception. Executables compiled with this compiler crash with a SEGV after throw(), never...
2
27768
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
5043
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
1883
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
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.