2017-03-25 5 views
0
INSERT INTO (
    SELECT student_info.Student_Name,scores.Final 
    FROM student_info 
    INNER JOIN scores ON scores.Student_id=student_info.Student_id 
     AND scores.Subject_id=1) 
(Student_Name,Final) VALUES("a",1) 

このようなもの.....私が達成したいのは、クエリされた結果に新しい行を追加し、その上にある列の平均を表示したいということです。クエリテーブルにINSERT関数を使用して行を挿入することはできますか?

+0

あなたはどこですか平均を訴える? – Barmar

+0

1回の操作で複数のテーブルに挿入することはできません。 – Barmar

+0

それがあなたがやろうとしていることでないなら、私はこの質問が何を求めているのか理解できません。 – Barmar

答えて

0

あなたは、インサートが必要な場合は

INSERT INTO your_table_name (Student_Name,Final) 
SELECT student_info.Student_Name,scores.Final 
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
AND scores.Subject_id=1 

この方法を使用することができますし、追加された行を必要とする最終的ならば、あなたの選択

INSERT INTO your_table_name (Student_Name,Final) 
SELECT student_info.Student_Name,scores.Final 
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
AND scores.Subject_id=1 
union all 
select "a", 1 
from dual; 
+0

'INSERT INTO'の後にテーブル名が必要です。 – Barmar

+0

@Barmar多くのありがとう..テーブル名refが追加されました – scaisEdge

+0

@scaisEdge私の場合は、クエリ結果に行を挿入したいと思います...クエリ結果に名前を付けることは可能ですか? – Sai

1

使用するようにリテラル値を持つUNION句を追加することができます選択UNION 2つのクエリの結果を1つの結果にまとめる:

SELECT student_info.Student_Name,scores.Final 
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
    AND scores.Subject_id=1 

UNION 

SELECT "a", AVG(scores.Final) 
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
    AND scores.Subject_id=1 
関連する問題