MAX and GROUP BY Problem
Hi I am trying to execute the following query using an OracleCommand:
SELECT P.Name,P.Version,P.AssemblyName,P.AssemblyVersion FROM Plugin P
JOIN (SELECT Name,MAX(Version) AS Version FROM Plugin WHERE Disabled=0 GROUP BY Name) D ON P.Name=D.Name AND P.Version=D.Version
ORDER BY CASE WHEN P.AssemblyName LIKE '%resources%' THEN 0 ELSE 1 END
Every time I run it I get the following exception:
ORA-00979: not a GROUP BY expression
However when I run this in SQL Developer no error is returned and the results are as expected.
Hi,
On Further investigation I have found the problem lies in the LIKE statement, when the '%' are present the error is produced. However on removing the '%' no exception is raised, for example:
SELECT P.Name,P.Version,P.AssemblyName,P.AssemblyVersion FROM Plugin P
JOIN (SELECT Name,MAX(Version) AS Version FROM Plugin WHERE Disabled=0 GROUP BY Name) D ON P.Name=D.Name AND P.Version=D.Version
ORDER BY CASE WHEN AssemblyName LIKE '%resources%' THEN 0 ELSE 1 END
Error: ORA-00979: not a GROUP BY expression
This is an extract from the trace file:
Trace file c:\app\tim\diag\rdbms\orcl\orcl\trace\orcl_ora_2560.trc
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Windows NT Version V5.2 Service Pack 2
CPU : 1 - type 586, 1 Physical Cores
Process Affinity : 0x00000000
Memory (Avail/Total): Ph:1037M/2047M, Ph+PgF:1876M/2669M, VA:1271M/2047M
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 38
Windows thread id: 2560, image: ORACLE.EXE (SHAD)
*** 2008-10-01 11:48:22.234
*** CLIENT ID:() 2008-10-01 11:48:22.234
*** SERVICE NAME:() 2008-10-01 11:48:22.234
*** MODULE NAME:() 2008-10-01 11:48:22.234
*** ACTION NAME:() 2008-10-01 11:48:22.234
opiino: Attach failed due to ORA-12537
Trace file c:\app\tim\diag\rdbms\orcl\orcl\trace\orcl_ora_2560.trc
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Windows NT Version V5.2 Service Pack 2
CPU : 1 - type 586, 1 Physical Cores
Process Affinity : 0x00000000
Memory (Avail/Total): Ph:912M/2047M, Ph+PgF:1699M/2669M, VA:1224M/2047M
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 30
Windows thread id: 2560, image: ORACLE.EXE (SHAD)
*** 2008-10-09 10:25:57.482
*** SESSION ID:(133.7753) 2008-10-09 10:25:57.482
*** CLIENT ID:() 2008-10-09 10:25:57.482
*** SERVICE NAME:(orcl) 2008-10-09 10:25:57.482
*** MODULE NAME:(WindowsFormsApplication1.vshost.exe) 2008-10-09 10:25:57.482
*** ACTION NAME:() 2008-10-09 10:25:57.482
XCTEND rlbk=0, rd_only=1
WAIT #3: nam='SQL*Net message to client' ela= 33 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=156669369456
*** 2008-10-09 10:25:58.042
WAIT #3: nam='SQL*Net message from client' ela= 561231 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=156669930768
=====================
PARSING IN CURSOR #3 len=168 dep=1 uid=52 oct=47 lid=52 tim=156669947688 hv=337957580 ad='29fe2fa8' sqlid='a6u3yjca29nqc'
declare
m_stmt varchar2(512);
begin
m_stmt:='delete from sdo_geor_ddl__table$$';
EXECUTE IMMEDIATE m_stmt;
EXCEPTION
WHEN OTHERS THEN
NULL;
end;
END OF STMT
PARSE #3:c=0,e=368,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,tim=156669945936
BINDS #3:
=====================
PARSING IN CURSOR #5 len=33 dep=2 uid=52 oct=7 lid=52 tim=156669958521 hv=1949913731 ad='29fe2cd8' sqlid='3972rvxu3knn3'
delete from sdo_geor_ddl__table$$
END OF STMT
PARSE #5:c=0,e=99,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=1,tim=156669958489
BINDS #5:
EXEC #5:c=0,e=339,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=1,tim=156669958974
STAT #5 id=1 cnt=0 pid=0 pos=1 obj=0 op='DELETE SDO_GEOR_DDL__TABLE$$ (cr=0 pr=0 pw=0 time=0 us)'
STAT #5 id=2 cnt=0 pid=1 pos=1 obj=62986 op='TABLE ACCESS FULL SDO_GEOR_DDL__TABLE$$ (cr=0 pr=0 pw=0 time=0 us cost=2 size=0 card=1)'
EXEC #3:c=0,e=1165,p=0,cr=0,cu=0,mis=0,r=1,dep=1,og=1,tim=156669959224
XCTEND rlbk=0, rd_only=1
WAIT #4: nam='SQL*Net break/reset to client' ela= 35 driver id=1413697536 break?=1 p3=0 obj#=-1 tim=156669959556
WAIT #4: nam='SQL*Net break/reset to client' ela= 794 driver id=1413697536 break?=0 p3=0 obj#=-1 tim=156669960406
WAIT #4: nam='SQL*Net message to client' ela= 28 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=156669960506
*** 2008-10-09 10:26:00.585
WAIT #4: nam='SQL*Net message from client' ela= 2468066 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=156672428682
=====================
PARSING IN CURSOR #5 len=168 dep=1 uid=52 oct=47 lid=52 tim=156672446116 hv=337957580 ad='29fe2fa8' sqlid='a6u3yjca29nqc'
declare
m_stmt varchar2(512);
begin
m_stmt:='delete from sdo_geor_ddl__table$$';
EXECUTE IMMEDIATE m_stmt;
EXCEPTION
WHEN OTHERS THEN
NULL;
end;
END OF STMT
PARSE #5:c=0,e=101,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,tim=156672446082
BINDS #5:
=====================
PARSING IN CURSOR #3 len=33 dep=2 uid=52 oct=7 lid=52 tim=156672446966 hv=1949913731 ad='29fe2cd8' sqlid='3972rvxu3knn3'
delete from sdo_geor_ddl__table$$
END OF STMT
PARSE #3:c=0,e=99,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=1,tim=156672446935
BINDS #3:
EXEC #3:c=0,e=345,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=1,tim=156672447601
STAT #3 id=1 cnt=0 pid=0 pos=1 obj=0 op='DELETE SDO_GEOR_DDL__TABLE$$ (cr=0 pr=0 pw=0 time=0 us)'
STAT #3 id=2 cnt=0 pid=1 pos=1 obj=62986 op='TABLE ACCESS FULL SDO_GEOR_DDL__TABLE$$ (cr=0 pr=0 pw=0 time=0 us cost=2 size=0 card=1)'
EXEC #5:c=0,e=1319,p=0,cr=0,cu=0,mis=0,r=1,dep=1,og=1,tim=156672447883
XCTEND rlbk=0, rd_only=1
WAIT #4: nam='SQL*Net break/reset to client' ela= 33 driver id=1413697536 break?=1 p3=0 obj#=-1 tim=156672448189
WAIT #4: nam='SQL*Net break/reset to client' ela= 746 driver id=1413697536 break?=0 p3=0 obj#=-1 tim=156672448992
WAIT #4: nam='SQL*Net message to client' ela= 32 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=156672449093
*** 2008-10-09 10:26:05.561
WAIT #4: nam='SQL*Net message from client' ela= 4958604 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=156677407767
=====================
PARSING IN CURSOR #3 len=55 dep=0 uid=86 oct=42 lid=86 tim=156677408531 hv=2217940283 ad='0' sqlid='06nvwn223659v'
alter session set events '10046 trace name context off'
END OF STMT
PARSE #3:c=0,e=168,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=156677408498
EXEC #3:c=0,e=933,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=156677409605
Removing the '%'
SELECT P.Name,P.Version,P.AssemblyName,P.AssemblyVersion FROM Plugin P
JOIN (SELECT Name,MAX(Version) AS Version FROM Plugin WHERE Disabled=0 GROUP BY Name) D ON P.Name=D.Name AND P.Version=D.Version
ORDER BY CASE WHEN AssemblyName LIKE 'resources' THEN 0 ELSE 1 END
Error: None
Then i tried just having the ORDER BY without the JOIN
SELECT P.Name,P.Version,P.AssemblyName,P.AssemblyVersion FROM Plugin P
ORDER BY CASE WHEN AssemblyName LIKE '%resources%' THEN 0 ELSE 1 END
Error: None
So the problem seems to lie in having a GROUP BY with a LIKE in ORDERBY. Has anyone got any idea on what may be causing this?
Edited by: rishi@invar on Oct 9, 2008 10:18 AM
Edited by: rishi@invar on Oct 9, 2008 10:27 AM
Similar Messages
-
Cannot get wanted data with MAX and GROUP BY function
Hi
All
I have a table like below:
COLUMN TYPE
USER_ID VARCHAR2 (10 Byte)
PROCESS_ID VARCHAR2 (30 Byte)
END_TIME DATE(STAMP)
TO_LOC VARCHAR2 (12 Byte)
TO_LOC_TYPE VARCHAR2 (15 Byte)
FROM_LOC VARCHAR2 (12 Byte)
ITEM_ID VARCHAR2 (25 Byte)
CASES NUMBER (12,4)
LMS_UDA1 VARCHAR2 (250 Byte)
ZONE VARCHAR2 (2 Byte)
I only want get one record with all columns, only have one clause MAX(END_TIME)
But the other column have difference value.
when i use MAX(END_TIME) and GROUP BY USER_ID,PROCESS_ID,CASES,....
the sql didnot give one record,
It give many records
Please help me on this
Regards
SavenHi, Saven,
Sorry, it's unclear what you want.
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show your proiblem using commonly available tables, like those in the scott or hr schamas, then you don't have to post any sample data: just the results and the explanation.
Always say what version of Oracle you're using.
See the forum FAQ {message:id=9360002}
Are you trying to see all data related to the highest (that is, latest) end_time?
I think you want something like this, that finds all the ionformation about the employee with the latest hiredate:
WITH got_r_num AS
SELECT emp.*
, ROW_NUMBER () OVER (ORDER BY hiredate DESC NULLS LAST)
AS r_num
FROM scott.emp
SELECT * -- Or list all columns except r_num
FROM got_r_num
WHERE r_num = 1
;What do you want in case of a tie, that is, if 2 or more rows have the same latest end_time? You may need to add tie-breaking expressions to the analytic ORDER BY clause, and/or use RANK instead of ROW_NUMEBR -
Help with 655 Max and Possible Memory Problems...
Just recieved my 655 Max and have put my system together, but when I turn it on it makes a constant beeping sound. I tried taking out both memory sticks, lol, and turning it on and the sound stops, I tried putting in one memory stick and the sound starts again.
I suppose this is a memory problem.
by the way I am using Corssair 256mb CMX256a-3200C2 memory.[The alarm that you are getting is the CPU Fan Alarm you will have to diable it in the Bios. I am using a Vantec Aeroflow heatsink and my CPU alarm also is constantly on and was very annoying till I disabled it. My system still doesn't boot to XP yet as I have RMA'd bothe the MB and Ram. QUOTE]Originally posted by TritonB7
Hey Kaiguy the comp does continue to make sounds till I shut the system off. And I'm not sure how a standard pc tone sound would sound like, :(. But it does make beep followed by a lower pitched beep, and it repeats this till I shutdown the system.
(1) I cannot Access Bios.
(2) I have two sticks of Corsair 256mb CMX256a-3200C2 memory. I do not have any other ram available that will be compatible with this motherboard. Ive tried using one stick at a time in each of the slots. No Luck.
I highly think that both sticks not working is very unreal.
(3) and reseting bios by the jumper isnt working either.
I can probably try buying some diffrent memory, or returning the whole mobo and exchanging it for the same one.
By the way on my monitor when i turn the comp on it says 8x Extreme or something close to it while the comp is beeping. I doubt that, that has anything to do with it. This is my first MSI board :( , I've always been an Asus person but Im still open for MSI i'm sure I just recieved a faulty board.
[/QUOTE] -
TV miglia max and iMac G4: problems
Hi all,
I have a problem with my Mac G4 1Ghz. I brought the new Tv Miglia Max but I can't install it( it doesn't finish the guided installation). My model should have 3 USB 2.0 ports but it seems the computer doesn't "see" tv miglia Max.
Someone could help me?
Thanks
PS.
On a iMac G5 installation was succesfulHello and Welcome to Apple Discussions.
Are you using a Universal Binary version or a PowerPC version through Rosetta?
EyeTV2.3 is just out so try downloading that.
mrtotes -
Problem in creating group above AND group left in one report!
Hi all,
I need a report that is a combination of group above and group
left.
Suppose I have 3 table (Emp, Sales, Product):
Emp Table has 2 column
- Emp_PK
- Emp_Name
Sales Table has 4 column
-Sales_PK
-Sales_Date
-Emp_FK
-Produck_FK
-Quantity
Product Table has 3 column
-Product_PK
-Product_Name
-Product_Price
I want to make Employee Sales Report For The Month that will
look like this:
Emp Number___: Emp_PK
Emp Name_____: Emp_Name
Sales Date______Product_Name____Quantity \(2 sales
________________Product_Name____Quantity /the date)
Sales_Date______Product_Name____Quantity
As you can see this consist of group above (The Employee) and
group left (The Sales and Product).
I create this by using 2 queries and link them (the Emp_PK from
1st query and Emp_FK from 2nd query) on the report builder using
data link.
The first query is:
Select Emp_PK, Emp_Name from Emp
The second query is
Select Emp_FK, Sales_Date, Product_Name, Quantity
From Sales, Product
Where Product_PK=PRODUCT_FK
I then create the layout for second query and choose group left
for Sales_Date using wizard and I create additional layout to
for the employee.
The problem is that when I run this report, it will print ALL
the employee record first (including employee who has NOT sale
anything) and then on the last page it will print the record of
Last employee on the Emp table and ALL sales record (including
those that is done by other employee).
This report will run correctly if I choose an exact employee
(For example by adding Where Emp_PK=1111 in the first query) to
report all of the sales done by this person (employee with emp
number of 1111). However I need the report to run and print
ONLY those employee who has Sales Records!
I thought that by linking the 2 queries in Data Model, it will
have the same effect as linking using the WHERE clause in query.
If suppose I create a query like this:
SELECT Emp_PK, Emp_Name, Sales_Date, Product_Name, Quantity
FROM Emp, Sales, Product
WHERE Emp_PK=Emp_FK AND Product_PK=Product_FK
The report will run OK but I can only choose EITHER group above
or group left for this ONE query methods in report Wizard.
Sorry if it is a long question but I hope you can see what I am
trying to do.
Thanks in advance for any tip.hello,
of course you can create group left and group above blocks in a
single report.
you might want to use the INSERT REPORT BLOCK instead of the
report wizard, as the report wizard only allows you to use one
report layout per report, where the report block wizard (invoked
by INSERT REPORT BLOCK) allows you to choose on a per-block
basis.
of course you can create the blocks completely from scarth by
hand, if you want to.
regards,
the oracle reports team --pw -
Displaying actual Max and Min in the report header problem...
Hi guys,
I have the following problem.
1. I have a multi select prompt where you pick 2 years.
2. I have the following columns. Year, Month, Exp, calc YEAR (max), calc year (min)
3. I need to get the max and min month across all rows. So far I've tried MAX, MIN, RMAX, and RMIN without success. However, it's not picking them along all rows. For example,
2001 1 100050 2001 2001
2002 1 244005 2002 2002
I'm sure this has to do something with my aggregation in the calculated column, but not quite sure where exactly.do max(max(year)) and min(min(year))
:) -
i got problem with volume of calls...its on max and i still can hear person on other side really bad...i got 4s
Did you fix the problem? I have the same problem and it has been pain in the neck.
-
Iphone and droid group message problem
I recently got the iphone 6. I have a group text comprised of iphone and non iphone users. If the discussion is just between the non iphone users the messages send properly (as a sms). However, when an iphone user responds it automatically converts to iMessage and non iphone users stop receiving the group txt. HELP!?!?!
I had an iphone 5 and switched to Samsung galaxy S5 in August 2014. Went through all the processes of de-registering number with apple imessage and had no problems with getting group messages from iPhone users. Then, about beginning of January, no longer could receive group messages from my iPhone friends. A couple have upgraded to the 6 but others had not. I have a pending case with ATT support, worked with Samsung support and did a factory reset, still no fix. I had two of my friends turn off iMessage today and send the group text, guess what? IT WORKED. So I totally agree, something has happened, maybe with a recent iOS update, not sure. But, they cannot send me group texts with iMessage turned on. Need help because I cannot afford to switch back to iPhone just so I can group text, but I'm getting left out of important information and events. VERY FRUSTRATED!!!!!!
-
Page and group Import and export problems
we are migrating from portal 3.0.6
(part of ias 1.0.2.0.1)
to
3.0.8(part of iAS 1.0.2.1).
OS:Solaris 2.6
The exports from 306 works fine.
when i imported security data for users and groups(secimp.csh) it swapped the users for two groups
i get the following error when i try to import pages
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "PORTAL30.WWUTL_POB_TRANSPORT", line 1879
ORA-01403: no data found
ORA-06512: at line 6
Anybody has this problem?
Thanks
nullHmm.. export/import only works between portal installations at the same version level. What you need to do is to use the upgrade scripts that will take you from Portal 3.0.7 to Portal 3.0.8, which are not available yet. We hope to make these scripts available in a couple of weeks on OTN. (Yes.. I too am waiting for these scripts).
Best Regards,
Harry Wong -
HELP Audio problem when setting windows volume at max and media player at max
im using msi eclipse x58
whenever i set my windows volume at max and media player at max also, after few seconds it suddenly not hearing audio but my media player is still playing
on other applications like skype wenever i set windows volume at max and after few seconds of voice chat with my friend the error says audio device disconnected.
On game applications while playing game same thing happens audio is gone
it is really stressful can someone pls help me out thanksQuote from: NovJoe on 17-February-10, 17:01:40
Please list out your full system specs and PSU specs amps for verification first.
My Power Supply is Cooler Master Real Power 550W
i7 core 920
Nvidia GTS 250
hard drive
320gb
640gb
2x 2gb 1333 ddr3 ram -
Identifying and grouping consecutive rows in sql
I have following data set:
CREATE TABLE APPS.T1
ROW_NUM NUMBER,
EFFECTIVE_START_DATE DATE NOT NULL,
EFFECTIVE_END_DATE DATE NOT NULL,
STATUS VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(1, TO_DATE('07/01/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('09/06/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(2, TO_DATE('03/20/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/31/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(3, TO_DATE('08/06/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/22/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(4, TO_DATE('08/23/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/26/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(5, TO_DATE('08/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
COMMIT;
SELECT * FROM APPS.T1
ROW_NUM EFFECTIVE EFFECTIVE STATUS
1 01-JUL-09 06-SEP-09 VAC
2 20-MAR-11 31-MAR-11 VAC
3 06-AUG-11 22-AUG-11 VAC
4 23-AUG-11 26-AUG-11 VAC
5 27-AUG-11 27-AUG-11 VAC
5 rows selected.My requirement was that row number 3, 4 and 5 be grouped and treated as a single vacation record such that
effective_start_date = 06-AUG-2011 and
effective_end_date = 27-AUG-2011
For this I wrote a query:
SELECT effective_start_date,
effective_end_date,
CASE
WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
THEN 0
WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
THEN 0
ELSE 1
END row_num
FROM (SELECT * FROM T1)Now the data returned looks like:
EFFECTIVE EFFECTIVE ROW_NUM
01-JUL-09 06-SEP-09 1
20-MAR-11 31-MAR-11 1
06-AUG-11 22-AUG-11 0
23-AUG-11 26-AUG-11 0
27-AUG-11 27-AUG-11 0
5 rows selected.Now I can easily use MIN(effective_start_date) and MAX(effective_start_date) group by ROW_NUM to achieve the desired results
SELECT MIN (effective_start_date) start_dt,
MAX (effective_start_date) end_dt,
row_num
FROM (SELECT effective_start_date,
effective_end_date,
CASE
WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
THEN 0
WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
THEN 0
ELSE 1
END row_num
FROM (SELECT *
FROM t1))
GROUP BY row_num
HAVING row_num = 0
UNION
SELECT effective_start_date start_dt,
effective_start_date end_dt,
row_num
FROM (SELECT effective_start_date,
effective_end_date,
CASE
WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
THEN 0
WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
THEN 0
ELSE 1
END row_num
FROM (SELECT *
FROM t1))
WHERE row_num = 1
START_DT END_DT ROW_NUM
01-JUL-09 01-JUL-09 1
20-MAR-11 20-MAR-11 1
06-AUG-11 27-AUG-11 0
3 rows selected.All done BUT the problem is that there may be several groups of consecutive rows like this. In that case each group should be identified distinctly for GROUP BY clause to work as expected.
I want to assign a unique number to each occurence of such group.
How can I achieve this? Any ideas?
Regards,
Faraz
Edited by: faanwar on May 10, 2012 3:36 PMWell, actually, you'll need to tweak it a bit. something such as in :Scott@my11g SQL>l
1 with t (id, dstart, dend, status)
2 as (
3 select 1,to_date('01-JUL-09','dd-MON-YY'),to_date('06-SEP-09','dd-MON-YY'),'VAC' from dual
4 union all select 2,to_date('20-MAR-11','dd-MON-YY'),to_date('31-MAR-11','dd-MON-YY'),'VAC' from dual
5 union all select 3,to_date('06-AUG-11','dd-MON-YY'),to_date('22-AUG-11','dd-MON-YY'),'VAC' from dual
6 union all select 4,to_date('23-AUG-11','dd-MON-YY'),to_date('26-AUG-11','dd-MON-YY'),'VAC' from dual
7 union all select 5,to_date('27-AUG-11','dd-MON-YY'),to_date('27-AUG-11','dd-MON-YY'),'VAC' from dual
8 )
9 ------ end of sample data ------
10 select min(dstart) dstart, max(dend) dend, status, count(*) aggrows
11 from (
12 select
13 id
14 ,dstart
15 ,dend
16 ,status
17 ,dend
18 -sum(dend-dstart) over (partition by status order by dstart)
19 -row_number() over (partition by status order by dstart) grp
20 from t
21 )
22 group by grp, status
23* order by grp, status
Scott@my11g SQL>/
DSTART DEND STA AGGROWS
01/07/2009 00:00:00 06/09/2009 00:00:00 VAC 1
20/03/2011 00:00:00 31/03/2011 00:00:00 VAC 1
06/08/2011 00:00:00 27/08/2011 00:00:00 VAC 3 -
SQL Query - Max Date - Group By
Please see SQL below - this code is counting customers and grouping by their tenure since activation
However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of records
SELECT TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
FROM FACT_RESULT_VW a,
PLAN_VW b,
SUB_VW c ,
CUST_VW d,
FACT_TRANS e,
WHERE e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )+
AND a.PP_KEY = b.PP_key
AND a.ID = c.ID
AND c.CUST_ID = d.CUST_ID
AND c.ID = E.ID
AND c.DATE_JOIN >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND c.DATE_JOIN < To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND a.DATE_KEY = 20100601
AND A.PEF_ID = 1
GROUP BY TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')Hi,
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
Simplify the problem as much as possible.
Would you have the same problem if only two tables, fact_result_vw and fact_trans, were involved? Then post a question involving only those two tables. Once you have a solution for the simplified problem, adding the other tables will be easy.
Would the problem be essentially the same if you were pivoting only 2 or 3 columns, instead of 13? Then post a question where you're only pivoting 2 or 3 columns. Once you have a solution, adding the others will be easy.
787771 wrote:
Please see SQL below - this code is counting customers and grouping by their tenure since activation
However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of recordsDo you want only the latest transaction from the fact_trans table, or the latest transaction for each customer ?
What if there's a tie, and the same customer has two (or more) transactions at the same date, and none later?
Since you're not using any of the data from the fact_trans table, the effect is just to eliminate customers who are not in fact_trans. You can do that more simply with an IN or EXISTS sub-query.
If you really do need something from the fact_trans table in the main table, then one way you can get the results you want is to use the analytic RANK (or ROW_NUMBER) function to number the rows in fact_trans by trans_date (latest first), with a separate set of numbers (1, 2, 3, ...) for each customer, like this:
WITH fact_trans_1 AS
SELECT id -- all columns that you need
, RANK () OVER ( PARTITION BY id
ORDER BY date_trans DESC
) AS r_num
FROM fact_trans
SELECT TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
FROM FACT_RESULT_VW a,
PLAN_VW b,
SUB_VW c,
CUST_VW d,
FACT_TRANS_1 e,
WHERE e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )
AND e.r_num = 1
AND a.PP_KEY = b.PP_key
AND a.ID = c.ID
AND c.CUST_ID = d.CUST_ID
AND c.ID = E.ID
AND c.DATE_JOIN >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND c.DATE_JOIN < To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
AND a.DATE_KEY = 20100601
AND A.PEF_ID = 1
GROUP BY TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')I hope this answers your question.
If not, post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data. -
is there a maximum number of contacts? is there a max # of contacts per group?
i want to set up some large email lists - if there is a max on verizon.net , will it work if i do it in outlook?
Solved!
Go to Solution.For your verizon.net addressbook, you have a max of 300 entries. That includes individuals AND groups. So if you have 38 contacts and two groups, that makes 40 entries. If you use an email client, you will not have this restriction.
You cannot send to more than 100 contacts at a time using Verizon's servers, and no more than 500 in an hour. This is stated in their email policy here.
The following limits apply with respect to the sending of e-mail from your verizon.net e-mail account. These rules are in place in order to help fight spam (i.e., unsolicited e-mail). For more information on Verizon Online's efforts to fight spam, please see the Verizon Online Anti-Spam Policy.
You may not include more than 100 recipients in a single email. Messages will not be sent to any recipients in excess of 100.
You may not exceed 500 recipients in 1 hour. Exceeding 500 recipients in 1 hour will result in the suspension of your ability to send email for 24 hours. This does not affect your ability to receive email.
It is important to note that the restrictions on the number of recipients/messages apply regardless of whether you use verizon.net or an email client. If you need to send more messages, I'd suggest finding another outgoing server to use.
If a forum member gives an answer you like, give them the Kudos they deserve. If a member gives you the answer to your question, mark the answer as Accepted Solution so others can see the solution to the problem.
"All knowledge is worth having." -
Min and Max and insert new rows
Hello,
I am really a beginner in Excel (2007). I am not sure if this is the correct forum, anyway.
I have grouped some rows in a sheet (rows 1, 2 and 3, columns A and B, table below), some of the columns have numeric values in that group and I have a row (inside that group) that shows the maximum and minimum values (row 1):
A B
+ 1 43 12 <- MAX and MIN values for row 2 and 3 columns A and B
+ 2 34 12
+ 3 43 34
I am using MAX and MIN functions: A1 = MAX($A2:$A$3), B1 = MIN($B$2:$B$3)
The problem comes when I want to insert more rows after row 3, the formula keeps wrapping to A$2:$A$3 therefore I need to readjust the formula to: MAX($A2:$A$4) manually (for MIN is the same).
A B
+ 1 43 12 <- Are the same, they should be
"98 and 10"
+ 2 34 12
+ 3 43 34
+ 4 98 10 <- New row, but the maximum and minimum continues to be the same, I want to extend the formula automatically to the 4 row when I insert the new row.
Question:
How can I extend the function of the MAX and MIN formula automatically when I insert new rows?
Please consider that I may insert rows at the beginning, in the middle or the end.
Thanks,
Enrique.
Kikeman Electric Systems EngineerHi Enrique,
Thanks for posting in MSDN.
Based on the description, you want to modify the formula for the A1 and B1 cell when you insert a new rows.
Yes, we can use Worksheet.Change to dermin the change of data on the worksheet then we can modify the formula as we wanted. Here is a sample for your reference:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("A1").Formula = "=MAX($A2:$A" & Me.UsedRange.Rows.Count & ")"
Me.Range("B1").Formula = "=MIN($B2:$B" & Me.UsedRange.Rows.Count & ")"
End Sub
You can more detail about Excel VBA developing from link below:
Getting Started with VBA in Excel 2010
Welcome to the Excel 2013 developer reference
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Sorting and Grouping -Two months in this query
Hi All,
many thanks for jeneesh
i am doing project for construction company, i face this problem in grouping points according to relation between these points the
Relation is from 1 to 100. If the point between this rang that mean there is relation between these points.
this question already solve but the results not correct when the table has more data.
SQL - sorting and grouping.
from jeneesh and many thanks for him.
This example for more clarifications
for example i have these points
id location percentage comments
1 loc 1,2 20% that mean point 1 and 2 close to each other by 20%
2 loc 1,3 40% that mean point 1 and 3 close to each other byy 40%
3 Loc 8,6 25% that mean point 8 and 6 close to each other by 25%
4 Loc 6,10 20%
5 LOC 11,10 10 %
6 LOC 15,14 0%Also , we can see the relation between these points as follwoing
- points 1,2,3 in one group why becuase 1,2 has relation and 1,3 has relation that mean 1,3 also has hidden relation.
- Points 6,8,10,11 in second group there are relations between them .
- but no relation between 1 or 2 or 3 with any point of 6,8,9,10,11
- as well as no relation between 15, 14 that mean 14 in third group and 15 in fourth group.
whati need?
to group the points that has relation according to percentage value ascending
The most important part is to group the points. SO , the below query the gropuing is not correct.
I have the follwoing table with data
drop table temp_value;
create table temp_value(id number(10),location varchar2(20), percentage number(9));
insert into temp_value values (1,'LOC 1,2',10);
insert into temp_value values (2,'LOC 1,3',0);
insert into temp_value values (3,'LOC 1,4',0);
insert into temp_value values (4,'LOC 1,5',0);
insert into temp_value values (5,'LOC 1,6',0);
insert into temp_value values (6,'LOC 2,3',0);
insert into temp_value values(7,'LOC 2,4',0);
insert into temp_value values (8,'LOC 2,5',30);
insert into temp_value values (9,'LOC 2,6',0);
insert into temp_value values (10,'LOC 3,4',0);
insert into temp_value values (11,'LOC 3,5',0);
insert into temp_value values (12,'LOC 4,5',40);
insert into temp_value values (13,'LOC 4,6',0);
insert into temp_value values (14,'LOC 6,7',40);
insert into temp_value values (15,'LOC 7,2',0);
insert into temp_value values (16,'LOC 8,2',60);
insert into temp_value values (17,'LOC 8,3',0);
insert into temp_value values (18,'LOC 3,1',0);
insert into temp_value values (19,'LOC 9,6',30);
insert into temp_value values (20,'LOC 11,2',0);
insert into temp_value values (22,'LOC 12,3',10);
insert into temp_value values (23,'LOC 19,3',0);
insert into temp_value values (24,'LOC 17,3',0);
insert into temp_value values (24,'LOC 20,3',0);when i used this query , the results is not correct
with t as
(select percentage,loc1,loc2,sum(case when percentage = 0 then 1
when loc1 in (l1,l2) then 0
when loc2 in (l1,l2) then 0
when l1 is null and l2 is null then 0
else 1
end) over(order by rn) sm
from ( select id,location,percentage,
regexp_substr(location,'\d+',1,1) LOC1,
regexp_substr(location,'\d+',1,2) LOC2,
lag(regexp_substr(location,'\d+',1,1))
over(order by percentage desc) l1,
lag(regexp_substr(location,'\d+',1,2))
over(order by percentage desc) l2,
row_number() over(order by percentage desc) rn
from temp_value
order by percentage desc
select loc,min(sm)+1 grp
from(
select loc,rownum rn,sm
from(
select percentage,decode(rn,1,loc1,loc2) loc,sm
from t a,
(select 1 rn from dual union all
select 2 from dual ) b
order by percentage desc,decode(rn,1,loc1,loc2) asc
group by loc
order by min(sm),min(rn);the results
SQL> /
LOC GRP
2 1
8 1
6 2
7 2
4 3
5 3
9 4
1 5
12 6
3 6
11 13
LOC GRP
19 14
17 15
20 22
14 rows selected.SQL>
but the correct is
Location group No
2 1
8 1
4 1
5 1
1 1
6 2
7 2
9 2
12 3
3 3
19 4
17 5
20 6many thanks in advance.
Edited by: Ayham on Nov 30, 2012 3:07 AMThanks,
i want the sorting for each group DESC not all groups to gather
when i used your query i get
SQL> with connects as (
2 select distinct
3 loc1
4 ,loc2
5 ,dense_rank() over (order by connect_by_root(loc1)) grp
6 from temp_value
7 start with
8 percentage != 0
9 connect by nocycle
10 (prior loc2 = loc1
11 or
12 prior loc1 = loc2
13 or
14 prior loc1 = loc1
15 or
16 prior loc2 = loc2)
17 and
18 percentage != 0
19 )
20 , got_grp AS
21 (
22 select
23 loc
24 ,dense_rank() over (order by grp) grp
25 from (
26 select
27 loc
28 ,max(grp) keep (dense_rank first order by grp) grp
29 from (
30 select
31 loc1 loc
32 ,grp
33 from connects
34 union
35 select
36 loc2
37 ,grp
38 from connects
39 )
40 group by
41 loc
42 )
43 )
44 SELECT loc
45 , grp
46 FROM got_grp
47 ORDER BY COUNT (*) OVER (PARTITION BY grp) DESC
48 , grp
49 , loc
50 ;The output is
LOC GRP
1 1
2 1
4 1
5 1
8 1
6 3
7 3
9 3
12 2
3 2
10 rows selected.but i want it like this
Loc Grp
2 1
8 1
4 1
5 1
1 1
12 2
3 2
6 3
7 3
9 3So , the sorting for each group Separate based on the percentage column.
many thanks
Edited by: Ayham on Nov 30, 2012 9:43 AM
Maybe you are looking for
-
Hi, I am new to programming. I have a sensor that sends a data stream through a serial port. I have collect all that data in a 1D unsigned byte array. Now, lets say my 1-D array is [12][45][65][12]...... where each "[ ]" is a element of the array. N
-
Dynamic date range in the variant
Hi, We have a background job that is scheduled to run on every 25th. One step of the job has a selection screen which has a Payment date range which is to have the dates 25th of previous to the 24th of the current month. So every month this needs to
-
Adobe AIR Windows app instance control
Hello! I´have an old Adobe AIR Windows app. How can I prevent multiple instances of the app. For example one user account launches the app on login, then on a user switch a new instance is started. I want only one instance of the app running. I come
-
Where is the Terminal config file?
Hello, I am trying to add a simple alias as a default to Terminal. Where is the configuration file? I can't find it anywhere. Thanks!
-
I need the number for account security to activate my account
Could someone give me the number of iTunes account security to activate my account. I can't update all my apps coz I had unauthorized pruchased and the disqbled my account. I got Ia response from apple support to contact account security of iTunes bu