| Table Updates [message #633602] |
Mon, 23 February 2015 01:14  |
Genesys
Messages: 45 Registered: August 2010
|
Member |
|
|
Hi,
here the below scenario and I could not provide the table struc & data because im working in remote system.
table struc & data.
uid type partition
abc 1 need to update
abc 2 need to update
xyz 3 need to update
xyz 1 need to update
asd 3
asd 1
fgh 3
fgh 1
by using the group by we can get the below data
uid type partition
abc 3 ?
xyz 4 ?
asd 4 ?
fgh 4 ?
here we need to update the partition value. if the sum of the TYPE for ABC,XYZ value is <=10 then partition value is 1 ,if its >10 then next partition i.e 2
uid type partition
abc 3 1
xyz 4 1
asd 4 2
fgh 4 2
Thanks
Gen
|
|
|
|
| Re: Table Updates [message #633603 is a reply to message #633602] |
Mon, 23 February 2015 01:17   |
John Watson
Messages: 9005 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Is this another college homework question?
You can provide the table structures. You can use DESCRIBE to show them.
You can also enclose your code in [code] tags, as you have been asked many times.
[Updated on: Mon, 23 February 2015 01:17] Report message to a moderator
|
|
|
|
| Re: Table Updates [message #633604 is a reply to message #633603] |
Mon, 23 February 2015 01:24   |
Genesys
Messages: 45 Registered: August 2010
|
Member |
|
|
Hi,
either its not college home work or interview question.
As mentioned Im working in remotely.more over need some logic to display the data rather than the table describe
Thanks
Gen
|
|
|
|
| Re: Table Updates [message #633605 is a reply to message #633604] |
Mon, 23 February 2015 01:26   |
John Watson
Messages: 9005 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Perhaps someone else is prepared to assist someone so intransigent. My life is too short for that.
Goodbye.
|
|
|
|
|
|
| Re: Table Updates [message #633613 is a reply to message #633606] |
Mon, 23 February 2015 03:40   |
Genesys
Messages: 45 Registered: August 2010
|
Member |
|
|
CREATE TABLE uid
(
a VARCHAR2(10),
b NUMBER,
c NUMBER
);
INSERT INTO uid
(a,
b)
VALUES ('p1',
4);
INSERT INTO uid
(a,
b)
VALUES ('p2',
5);
INSERT INTO uid
(a,
b)
VALUES ('p3',
5);
INSERT INTO uid
(a,
b)
VALUES ('p4',
5);
INSERT INTO uid
(a,
b)
VALUES ('p5',
3);
INSERT INTO uid
(a,
b)
VALUES ('p6',
5);
Excepted O/p
a b c
p1 4 1
p2 5 1 4+5=9 <10 then 1
p3 5 2 9+5=14 >10 then 2, p3 b value is 5 now
p4 5 3 (p3)5+(p4)5=10 not < 10 then 3 ,p4 b value is 5
p5 3 3 5+3=8 <10 then 3
p6 4 4 8+4=12 >10 then 4
Hope this is clear
Thanks
Gen
|
|
|
|
|
|
|
|
|
|
| Re: Table Updates [message #633626 is a reply to message #633624] |
Mon, 23 February 2015 05:10   |
Genesys
Messages: 45 Registered: August 2010
|
Member |
|
|
a b c
p1 4 1
p2 5 1 4+5=9 <10 then 1
p3 5 2 9+5=14 >10 then 2, p3 b value is 5 now
p4 5 3 (p3)5+(p4)5=10 not < 10 then 3 ,p4 b value is 5
p5 3 3 5+3=8 <10 then 3
p6 4 4 8+4=12 >10 then 4
in third row:
9+5=14 its >10 then need to increment the C value from 1 to 2.if any changes in C value will carry the corresponding B value to next row
any How,I got the solution my self by creating some bit of pl/sql block.
Thanks
Gen
|
|
|
|
|
|
|
|
| Re: Table Updates [message #633640 is a reply to message #633613] |
Mon, 23 February 2015 10:44   |
Solomon Yakobson
Messages: 3312 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
First of all, UID is reserved word - you shouldn't be naming table UID. Anyway, MODEL solution:
select a,
b,
c
from uid_tbl
model
dimension by(row_number() over(order by a) rn)
measures(a,b,1 c,b s)
rules(
s[rn > 1] order by rn = case
when nvl(s[cv() - 1],b[cv() - 1]) + b[cv()] >= 10 then null
else nvl(s[cv() - 1],b[cv() - 1]) + b[cv()]
end,
c[rn > 1] order by rn = case
when s[cv()] is null then c[cv() - 1] + 1
else c[cv() - 1]
end
)
/
A B C
---------- ---------- ----------
p1 4 1
p2 5 1
p3 5 2
p4 5 3
p5 3 3
p6 5 4
6 rows selected.
SQL>
SY.
|
|
|
|
|
|
|
|
| Re: Table Updates [message #633653 is a reply to message #633647] |
Tue, 24 February 2015 00:39  |
Genesys
Messages: 45 Registered: August 2010
|
Member |
|
|
DECLARE
a NUMBER:=0;
p NUMBER:1;
BEGIN
FOR i IN
(SELECT UID,
SUM(b)cnt from uid_tbl group by uid)
LOOP a:=a+i.cnt;
IF a<10 THEN
UPDATE uid_tbl
SET c=p
WHERE UID=i.UID;
ELSIF a>=10 THEN
p:=p+1;
UPDATE uid_tbl
SET c=p
WHERE UID=i.UID;
a:=i.cnt;
END IF;
END LOOP;
END;
|
|
|
|