473,383 Members | 1,846 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,383 software developers and data experts.

"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.datetime),
acgr.group_code,
bank.local_acc_no,
bank.short_name,
DECODE
(bank.account_type,
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_no = bank.corr_acc_no
AND bank.corr_acc_no = item.corr_acc_no
AND item.corr_acc_no = note.corr_acc_no
AND item.gin = note.gin
AND item.flag_2 = 0
AND grup.group_code = 'GMSAZSGREC99'
and bank.account_type in (0)
group by acgr.group_code,
bank.local_acc_no,
bank.short_name,
bank.account_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
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.datetime)

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 5338

Try this:

select max(note.datetime),

acgr.group_code,

bank.local_acc_no,

bank.short_name,

DECODE

(bank.account_type,

,'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_no = bank.corr_acc_no

AND bank.corr_acc_no = item.corr_acc_no

AND item.corr_acc_no = note.corr_acc_no

AND item.gin = note.gin

AND item.flag_2 = 0

AND grup.group_code = 'GMSAZSGREC99'

and bank.account_type in (0)

group by

acgr.group_code,

bank.local_acc_no,

bank.short_name,

DECODE

(bank.account_type,

,'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
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...
14
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...
2
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 ...
5
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...
13
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...
2
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...
3
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...
1
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),...
5
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....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.