2017-04-05 202 views
0

我有两个表 “aux1.txt”SQL:删除空字符串

CREATE TABLE aux1 
    ( 
    "date/time"   DATE, 
    year     INTEGER, 
    month     INTEGER, 
    day     INTEGER, 
    "data quality"   TEXT, 
    "max temp"    REAL, 
    "max temp flag"  TEXT, 
    "min temp"    REAL, 
    "min temp flag"  TEXT, 
    "mean temp"   REAL, 
    "mean temp flag"  TEXT, 
    "heat deg days"  REAL, 
    "heat deg days flag" TEXT, 
    "cool deg days"  REAL, 
    "cool deg days flag" TEXT, 
    "total rain"   REAL, 
    "total rain flag"  TEXT, 
    "total snow"   REAL, 
    "total snow flag"  TEXT, 
    "total precip"   REAL, 
    "total precip flag" TEXT, 
    "snow on grnd"   REAL, 
    "snow on grnd flag" TEXT, 
    "dir of max gust"  REAL, 
    "dir of max gust flag" TEXT, 
    "spd of max gust"  REAL, 
    "spd of max gust flag" TEXT 
); 

与历史气象数据和另一个名为 “weather.txt的”

CREATE TABLE weather 
    ( 
    year   INTEGER, 
    month   INTEGER, 
    day   INTEGER, 
    "max temp"  REAL, 
    "min temp"  REAL, 
    "mean temp" REAL, 
    "total precip" REAL 
); 

用那些列。我只想在最大温度,最小温度,平均温度,总Precip字段都不为空的情况下,将aux1中的所有相关列插入天气。到目前为止,我已经有了:

INSERT INTO weather 
SELECT "max temp"  REAL, 
     "min temp"  REAL, 
     "total precip" REAL 
FROM aux1 
WHERE "max temp" IS NOT NULL 
     AND "max temp" <> "" 

,尽管它好像这个工程的“最高温度”我不知道如何继续这样做语法明智的所有其他人。任何方向感谢!

感谢

+0

如果'“ma x temp“'是一个'REAL',它将如何成为''”'? – vol7ron

回答

0

为什么不干脆:

... and "Min Temp" is not null and "Min Temp" <> "" ... etc. 
0
INSERT INTO weather 
SELECT "max temp"  REAL, 
     "min temp"  REAL, 
     "total precip" REAL 
FROM aux1 
WHERE "max temp"  IS NOT NULL AND 
     "min temp"  IS NOT NULL AND 
     "total precip" IS NOT NULL 
  • REAL不是字符串,所以没有理由去检查field <> ""
  • 然后,只需确保您的其他领域也没有null