MYSQL关于如何将值插入特定列表
这是我的表名MYSQL关于如何将值插入特定列表,mysql,Mysql,这是我的表名mam\u zip 列包括id、zipcode、cityname、countryname、statename、stateAbr、category 例如: 伪代码: if statename = 'New York' then insert 'Regional' in category if statename = 'California' then insert 'National' in category 有没有一种更短的方法可以在SQL中插入值,这样我就不会在列表类别中手动插入
mam\u zip
列包括id、zipcode、cityname、countryname、statename、stateAbr、category
例如:
伪代码:
if statename = 'New York' then insert 'Regional' in category
if statename = 'California' then insert 'National' in category
有没有一种更短的方法可以在SQL中插入值,这样我就不会在列表类别中手动插入值,因为这有很多记录
insert into mam_zip (category) values (regional)
或者干脆更新一下
update mam_zip
where statename = 'New York'
set catergory = 'Regional'
干杯您可以在以下情况下尝试使用case 您需要插入其他列的值
insert into mam_zip(id, zipcode, cityname, countryname, statename, stateabbr, category)
values(id,zipcode,cityname,countryname,statename,stateabbr,
case when statename='New York' then 'Regional'
when statename='California' then 'Natioanal' else statename end)
尝试有条件地填充
类别
列的查询
INSERT INTO mam_zip (<otherColumns....>,category)
SELECT <OtherColumns>,
CASE
WHEN statename = 'New York'
THEN 'Regional'
WHEN statename = 'California'
THEN 'National'
END
插入主拉链(,类别)
选择,
案例
当statename='纽约'
然后是“区域性”
当statename=‘California’时
然后是“国家”
结束
this works update mam_zip set catergory='Regional'其中statename='New York'谢谢@shalvin这些似乎是更新而不是插入!?!