简体   繁体   English

SQL子查询的多个下限值

[英]Multiple returend values of SQL sub-query

I am using PostgreSQL 9.1, I wrote the following SQL statement: 我正在使用PostgreSQL 9.1,我写了以下SQL语句:

INSERT INTO "Tracking" VALUES 
((SELECT "studentID" FROM "Student" WHERE "studentClass"='2'),false,4,false);

The issue is that the sub-query : 问题是子查询:

SELECT "studentID" FROM "Student" WHERE "studentClass"='2'

returned more than one value, and it is supposed to do that(I want to execute the main query per each returned value of sub-query), but by this way the Query will not be executed. 返回一个以上的值,并且应该这样做(我想对子查询的每个返回值执行主查询),但是通过这种方式将不会执行查询。 Any Idea? 任何想法?

Try this: 尝试这个:

INSERT INTO "Tracking" 
SELECT "studentID",false,4,false
FROM "Student" WHERE "studentClass"='2'

Then use INSERT INTO... SELECT statement 然后使用INSERT INTO... SELECT语句

INSERT INTO "Tracking" 
SELECT "studentID" , false , 4 , false
FROM   "Student" 
WHERE  "studentClass" = '2'

One thing to make sure about this statement is to make sure that table Tracking contains only 4 column or else you will getting number of columns mismatched with the supplied value. 确保此语句的一件事是确保表Tracking仅包含4列,否则您将获得与提供的值不匹配的列数。 If for instance you have more than 4 columns, define the column name on the INSERT clause on which you want to save those values. 例如,如果您有多于4列,则在要保存这些值的INSERT子句上定义列名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM