2014-11-04 174 views
-2

我試圖列出JR + SR學生通過他們的大,但它不工作..Sql查詢。嵌套與否?

SELECT 
    Std_Major, 
    Std_Class, 
    AVG(Std_GPA) 
FROM 
    Student 
WHERE 
    Std_Class LIKE 'JR%' AND Std_Class LIKE 'SR%' 
GROUP BY 
    Std_Major, 
    Std_Class; 
+3

我想你想'或',而不是'和'。沒有行可能有一列以「JR」和「SR」開頭的列。 – 2014-11-04 12:15:52

+0

我認爲你是對的,但我想要一個組合jr和sr,然後由主要 – qman111 2014-11-04 12:19:03

+1

組,我與@GordonLinoff去,你說std_class開始與JR和std_class開始SR太 – 2014-11-04 12:19:06

回答

2

也許使用的,而不是運營商和

1

SELECT Std_Major, Std_Class, AVG(Std_GPA) 
FROM Student 
WHERE Std_Class LIKE 'JR%' AND Std_Class LIKE 'SR%' 
GROUP BY Std_Major, Std_Class; 
這一翻譯

使用

SELECT Std_Major, Std_Class, AVG(Std_GPA) 
FROM Student 
WHERE Std_Class LIKE 'JR%' OR Std_Class LIKE 'SR%' 
GROUP BY Std_Major, Std_Class; 
2

在這種情況下,您必須使用

例子:

SELECT Std_Major, Std_Class, AVG(Std_GPA) 
FROM Student 
WHERE Std_Class LIKE 'JR%' OR Std_Class LIKE 'SR%' 
GROUP BY Std_Major, Std_Class;