for example:
My table is:
create table aaa {
a int not null auto_increment,
b int not null,
c varchar(255),
primary key (a,b)
}
Now, I want to insert a record
insert into aaa values (a,b,c)
((SELECT * from (select IFNULL(MAX(a)+1,1) as temp FROM aaa where b = 2) as P),
2,"what ever";
How can I achieve this?
The only solution I found is to make all of this become raw query in this page.
Can I write this something like that:
reault = Aaa.create({a: "(SELECT * from (select IFNULL(MAX(a)+1,1) as temp FROM aaa where b = 2) as P)", b: 2, c:"what ever"})
Only field a is used raw query and other part is wrote as usual?
rails: 4.2.1 DB gem is Mysql2
Aucun commentaire:
Enregistrer un commentaire