[英]how t use 'IF' in 'SELECT' statement with insert on mysql
我的桌子是
id_stuff | kd_insert | name_stuff | date_createdd
1 | 1 | example | 2018-01-01
我這樣在mysql中創建查詢
SELECT IF ((DATE_FORMAT(NOW(),'%Y-%m') > DATE_FORMAT(MAX(date_createdd),'%Y-%m')),
(
INSERT INTO tabless (name_stuff) VALUES ('stuff')
),
(
null
)
) FROM tabless GROUP BY id_stuff ORDER BY kd_insert
我跑步后為什么會出現這樣的錯誤
錯誤代碼:1064您的SQL語法錯誤; 查看與您的MySQL服務器版本相對應的手冊,以獲取在'INTO表(name_stuff)VALUES('stuff')附近使用的正確語法。
以及如何創建select with condition then insert
的正確select with condition then insert
? 謝謝
我認為不可能編寫這樣的插入語句。 你可以這樣做 -
SELECT
if(
(DATE_FORMAT(NOW(), '%Y-%m')) > DATE_FORMAT(MAX(date_createdd), '%Y-%m'),
(@value = 'stuff'),
null
)
FROM
tabless
GROUP BY
id_stuff
ORDER BY
kd_insert;
INSERT INTO tabless (name_stuff) VALUES ('stuff');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.