-- Rough Work for MMID Updation Automatically
CREATE TABLE main
(
sno serial NOT NULL,
mid integer,
mmid integer,
venue text,
CONSTRAINT pk_sno PRIMARY KEY (sno)
);
INSERT INTO main(mid, mmid, venue) VALUES(1, 1, 'Ramesh Gardens');
INSERT INTO main(mid, mmid, venue) VALUES(1, 2, 'Suresh Gardens');
INSERT INTO main(mid, mmid, venue) VALUES(1, 3, 'Kamesh Gardens');
INSERT INTO main(mid, mmid, venue) VALUES(2, 1, 'Rajesh Gardens');
INSERT INTO main(mid, mmid, venue) VALUES(2, 2, 'Rajesh Gardens');
根据mmid
值
1
更新为mid
此处mid
代表Meeting_ID
,mmid
代表SubMeeting_ID
。我试过像这样。
SELECT * FROM main;
INSERT INTO main(mid, mmid, venue) VALUES((SELECT MAX(mid) FROM main)+1,(SELECT MAX(mmid) FROM main WHERE mid=(SELECT MAX(mid) FROM main))+1,'Rajesh Gardens');
SELECT * FROM main;
答案 0 :(得分:1)
在表格中保留这样的值很难且容易出错,你确定你不想在某些视图中内联计算它:
select
sno, mid, venue, row_number() over(partition by mid order by sno) as mmid
from main