我有两个表,一个填充了数据
CREATE TABLE `tableX` (`column1` REAL);
INSERT INTO tableX VALUES (5);
INSERT INTO tableX VALUES (-3);
CREATE TABLE `tableY`
(`rowid` INTEGER PRIMARY KEY, `column2` REAL);
INSERT CASE语句是
INSERT INTO tableY SELECT column1,
CASE WHEN column1 >=0 THEN 1 ELSE 2 END as column2 FROM tableX;
错误是我的数据库浏览器中的“数据类型不匹配”,但似乎在sqlfiddle中工作...至少没有错误
非常感谢任何帮助!谢谢:D!
答案 0 :(得分:1)
不是最优雅的解决方案,但它是一种解决方法。
CREATE TABLE `tableX` (`column1` REAL);
INSERT INTO tableX VALUES (5);
INSERT INTO tableX VALUES (-3);
CREATE TABLE `tableZ` (`column1` REAL, `column3` REAL);
INSERT INTO tableZ SELECT column1,
CASE WHEN column1 >=0 THEN 1 ELSE 2 END as column3 FROM tableX;
CREATE TABLE 'tableY' (`rowid` INTEGER PRIMARY KEY, `column2` REAL)
INSERT INTO tableY (column2) SELECT column3 FROM tableZ;
DROP TABLE tableZ;