Find no. of times column value modified [message #604097] |
Tue, 24 December 2013 00:26 |
|
dhivyak
Messages: 6 Registered: December 2013
|
Junior Member |
|
|
Need Query to find out how many times column value is modified(insert/update) for a particular ID? Null values are also allowed
E.g:
table is as follows:
ID Col1
1 Y
1 N
1 N
1 N
2 NULL
2 Y
2 N
2 N
3 Y
3 Y
The desired output should be :
ID Col1
1 2(one insert and one update)
2 3(one insert and 2 updates)
3 1(one insert)
Any help would be appreciated.
Thanks
|
|
|
|
|
|
|
|
|
|
|
|
Re: Find no. of times column value modified [message #604116 is a reply to message #604111] |
Tue, 24 December 2013 04:10 |
|
dhivyak
Messages: 6 Registered: December 2013
|
Junior Member |
|
|
PFB the details
CREATE TABLE table1
(
ID NUMBER NOT NULL,
IND VARCHAR2 (1 BYTE),
C_DATE DATE
)
/
INSERT INTO table1 (id, ind, c_date)
VALUES (1, 'Y', SYSDATE)
/
INSERT INTO table1
VALUES (1, 'N', SYSDATE)
/
INSERT INTO table1
VALUES (2, NULL, SYSDATE)
/
INSERT INTO table1
VALUES (1, 'N', SYSDATE)
/
INSERT INTO table1
VALUES (2, 'Y', SYSDATE)
/
INSERT INTO table1
VALUES (1, 'N', SYSDATE)
/
INSERT INTO table1
VALUES (3, NULL, SYSDATE)
/
INSERT INTO table1
VALUES (2, 'N', SYSDATE)
/
INSERT INTO table1
VALUES (2, 'N', SYSDATE)
/
INSERT INTO table1
VALUES (3, 'Y', SYSDATE)
/
INSERT INTO table1
VALUES (3, 'Y', SYSDATE)
/
SELECT *
FROM TABLE1
ORDER BY Id
/
ID IND C_DATE
1 N 2/24/2013 3:18:12 PM
1 N 2/25/2013 4:21:30 PM
1 Y 2/26/2013 7:06:45 PM
1 N 2/27/2013 8:38:56 PM
2 NULL 2/27/2013 2:59:06 PM
2 Y 2/28/2013 1:16:13 PM
2 N 2/28/2013 8:07:34 PM
2 N 3/9/2013 3:42:30 PM
3 NULL 3/11/2013 9:19:23 PM
3 Y 3/25/2013 3:16:45 PM
3 Y 3/29/2013 3:16:45 PM
My Requirement is to write q query to find how many ID's have IND column inserted/updated
Output should be:
ID Count()
1 3
2 3
1 2
For ID 1 the record 1 is insert and record 3 and 4 are modified (but total 4 records)
For ID 2 the record 1 is insert and record 2 and 3 are modified (but total 4 records)
For ID 2 the record 1 is insert and record 2 is modified (but total 3 records)
|
|
|
|
|
|