-- 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;