基于条件的Mysql数据插入 [英] Mysql data insertion based on a condition
问题描述
我正在尝试根据另一个表字段值将一些值插入到新表中。
任何人都知道正确的语法,请帮助我..
i使用了这种语法。我知道这是无效的。
INSERT INTO tbl_cust_payments
VALUES( null,'+ dates +','+ sub_id +','+ cust_no +','+ amount +')
WHERE NOT EXISTS(SELECT * FROM tbl_subscriber_account WHERE tbl_subscriber_account.amount< = 0)
tbl_cust_payments和tbl_subscriber_account是两个表..
试试这样。
INSERT INTO tbl_temp2(fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id> 100 ;
了解更多详情查看本网站
http://dev.mysql.com /doc/refman/5.1/en/insert-select.html [ ^ ]
http://dev.mysql.com/doc/refman/5.6/en/insert-select.html [ ^ ]
http://stackoverflow.com/questions/9139003/insert -into-select-from-query-with-where-condition [ ^ ]
试试这个:
IF NOT EXISTS ( SELECT * FROM tbl_subscriber_account WHERE tbl_subscriber_account.amount< = 0 )
INSERT INTO tbl_cust_payments
VALUES ( null ,日期,sub_id,cust_no,金额)
希望它有所帮助! :)
i am trying to insert some values to a new table based on another table fields value..
any one know about the correct syntax for that please help me..
i used this syntax .i know this is not valid.
INSERT INTO tbl_cust_payments
VALUES(null,'" + dates + "','" + sub_id + "','" + cust_no + "','" + amount + "')
WHERE NOT EXISTS (SELECT * FROM tbl_subscriber_account WHERE tbl_subscriber_account.amount <= 0)
tbl_cust_payments and tbl_subscriber_account are the two tables..
Hi,
Try like this.
INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
for more details check this website
http://dev.mysql.com/doc/refman/5.1/en/insert-select.html[^]
http://dev.mysql.com/doc/refman/5.6/en/insert-select.html[^]
http://stackoverflow.com/questions/9139003/insert-into-select-from-query-with-where-condition[^]
Hi, try this:
IF NOT EXISTS(SELECT * FROM tbl_subscriber_account WHERE tbl_subscriber_account.amount <= 0) INSERT INTO tbl_cust_payments VALUES(null, dates, sub_id, cust_no, amount)
Hope it helps! :)
这篇关于基于条件的Mysql数据插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!