有什麼不對這個查詢:SQL查詢給錯誤
SELECT count() as total_students
FROM student_information;
SELECT
(
SELECT student_project_marks
from students_project
WHERE student_project_id=student_information.student_project_id
)
+ student_assignment_marks
+ student_exam_marks AS total_marks
FROM student_information
ORDER BY total_marks DESC;
UPDATE student_information
SET (
SELECT student_grade
FROM student_information
LIMIT 0.1*total_students
ORDER BY total_marks DESC
)="A";
蔭試圖選擇0.1*total_students
數所獲得的總標記下令學生和更新他們的成績....前10%將被評爲A. 我得到錯誤: syntax error near '('
我有2個表:
create table if not exists student_information (
student_name varchar(80),
student_roll_num int primary key,
student_email varchar(64),
student_assignment_marks int(2) check(student_assignment_marks<=30),
student_exam_marks int(2) check(student_exam_marks<=50),
student_project_id varchar(25),
student_grade varchar(2)
)
create table if not exist students_project (
student_project_id varchar(25),
student_project_title varchar(25),
student_project_marks int(2) check(student_project_marks>=0 and student_project_marks<=20)
)
: 通過下面的查詢創建它們
通過student_project_id
從student_project
表訪問項目中的標記。
現在我該如何根據總分數獎勵分數... 前10%必須被授予A,接下來的10%B等等...... 我知道如何計算總分數...... 我已經寫過這樣的查詢:
select student_roll_num,
(SELECT student_project_marks
from students_project
WHERE student_project_id=student_information.student_project_id)+
student_assignment_marks+student_exam_marks as total_marks from student_information;
它的工作原理。
我不確定你可以在任何RDBMS中的LIMIT子句中進行數學運算。你不需要聲明變量來存儲值嗎? – 2012-04-09 15:54:42
您的更新聲明有幾個問題。我不清楚你想要做什麼。 – 2012-04-09 15:58:23
您還想通過_count_更新前10%的學生,當需要按年級考慮時 - 如果15%的學生獲得相同的最高成績,會發生什麼情況?你會懲罰一個'隨機'5%的人口。 – 2012-04-09 16:01:17