Slt. a tous.

ce que je voudrais savoir, c´est s´il existe quelque chose du genre:

Ma_table
(ID_MA_table,tdoc,ndoc,nom)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
insert into Ma_table (tdoc,ndoc,nom) values 
(2,select max(ndoc)+1 from Ma_table where tdoc=2,"XXX")
je m´exlique:
je voudrais que ndoc soit un compteur de document, en funtion du tdoc( type du doc)
1 | 2 | 1 | XXXX
2 | 2 | 2 | YYY
3 | 1 | 1 | hhh

pour l´instant j´ai:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
start transaction;
lock table Ma_table write;
SELECT @A:=max(codigo)+1 from MA_table where tdoc =2;
insert into Ma_table (tdoc,ndoc,nom) values (2,@A,"XXX");
unlock tables;
commit;
mais je trouve qu´il doit avoir plus facile, vue que ce probleme doit arriver a
presque tous le monde... si quelqun me peut donner des idees...
merci...