我在将 check50 输出与我的代码匹配时遇到问题,尽管根据我的观点,它按年份和名称正确排序了陨石。此外,它从最古老的陨石中分配从 1 开始的 ID。 PSET3 链接 https://cs50.harvard.edu/sql/2024/psets/3/meteorites/
DROP TABLE IF EXISTS "meteorites_temp";
DROP TABLE IF EXISTS "meteorites";
CREATE TABLE "meteorites_temp" (
"name" TEXT,
"id" INTEGER,
"nametype" TEXT,
"class" TEXT,
"mass" REAL,
"discovery" TEXT,
"year" INTEGER,
"lat" REAL,
"long" REAL,
PRIMARY KEY("id")
);
CREATE TABLE "meteorites" (
"id" INTEGER,
"name" TEXT,
"class" TEXT,
"mass" REAL,
"discovery" TEXT,
"year" INTEGER,
"lat" REAL,
"long" REAL,
PRIMARY KEY("id")
);
.import --csv --skip 1 meteorites.csv meteorites_temp
UPDATE "meteorites_temp"
SET "mass" = NULL,
"year" = NULL,
"lat" = NULL,
"long" = NULL
WHERE "mass" = '' OR
"year" = '' OR
"lat" = '' OR
"long" = '';
UPDATE "meteorites_temp"
SET "mass" = ROUND("mass", 2),
"lat" = ROUND("lat", 2),
"long" = ROUND("long", 2);
DELETE FROM "meteorites_temp" WHERE "nametype" = 'Relict';
INSERT INTO "meteorites" ("name", "class", "mass", "discovery", "year", "lat", "long")
SELECT "name", "class", "mass", "discovery", "year", "lat", "long"
FROM "meteorites_temp"
ORDER BY "year", "name";
DROP TABLE "meteorites_temp";
我对 pset3 陨石遇到问题的步骤是:
4.陨石按年份排序,从最旧到最新,然后(如果有两个陨石在同一年着陆)按名称按字母顺序排列。 5.您已根据#4 中指定的顺序从meteites.csv 更新了陨石的ID。陨石的 id 应从 1 开始,从最古老年份着陆的陨石开始,并且按字母顺序排列是该年份的第一个陨石。
我只有这个要调试,这就是 check50 输出的内容:
:) import.sql exists
:) import.sql runs without error
:) import.sql creates a table named "meteorites"
:) import.sql creates a table named "meteorites" with all prescribed columns
:) data from CSV has been imported
:) no empty values from CSV are present in "meteorites" table
:) all decimal values in "meteorites" table are rounded to two places
:) no meteorites of type "relict" found in "meteorites" table
:( "meteorites" table properly sorts elements and assigns IDs
原因 应为“1,Apache Junc...”,而不是“1,阿德莱德,N...”
预期输出: 1、阿帕奇枢纽站,无 2、Asarco Mexicana,无 3、澳大利亚、无 4、贝拿勒斯 (b),无 5、卡西兰迪亚,无
实际产量: 1、阿德莱德、无 2、利斯河畔艾尔,无 3、艾伦山 03541,无 4、艾伦山 03542,无 5、昂热,无
我这样做了,瞧,它被接受了。我不知道这是怎么回事。我正确地编写了整个代码,但它仍然没有接受:|
UPDATE "meteorites_temp" SET
"mass" = NULLIF("mass", ''),
"year" = NULLIF("year", ''),
"lat" = NULLIF("lat", ''),
"long" = NULLIF("long", '');