我的select语句有什么问题?

时间:2013-03-29 14:15:21

标签: sql oracle

这是一个问题,请记住我正在使用SQL开发人员3 ....

学生服务部门希望了解每位教师在课外向学生提供建议时的参与程度。提供教师ID列表以及教师建议的学生人数。标题为教师ID“Faculty ID”的输出列,学生的输出列为“NumStuds”。仅当教师ID小于100并且学生在姓氏或名字字段中输入值时才生成输出。按教师ID

按递增顺序显示输出

这就是我得到的......

SELECT F_ID AS "Falculty ID" , COUNT S_ID AS "NumStud" FROM student
WHERE ( s_first, s_last, f_id ) IS NOT NULL
AND IS <= 100
ORDER BY F_ID ACD

然后我收到错误错误从命令行的第329行开始:

SELECT F_ID AS "Falculty ID" , COUNT S_ID AS "NumStud" FROM student
WHERE ( s_first, s_last, f_id ) IS NOT NULL
AND IS <= 100
ORDER BY F_ID ACD
  

命令行错误:329列:42错误报告:SQL错误:   ORA-00923:未找到FROM关键字   00923. 00000 - “找不到FROM关键字”

请帮助!

2 个答案:

答案 0 :(得分:1)

由于您正在测试 null 值,因此无法执行此操作。它应该手动测试。

SELECT F_ID AS "Falculty ID" , COUNT(S_ID) AS "NumStud" 
FROM student 
WHERE   (
            s_first IS NOT NULL OR 
            s_last IS NOT NULL OR
            f_id  IS NOT NULL
        ) AND IS <= 100 
ORDER BY F_ID ASC

其次,对于升序而不是ASC

应该{​​{1}}

答案 1 :(得分:1)

尝试:

SELECT F_ID AS "Faculty ID" , COUNT(S_ID) AS "NumStud" 
FROM student
WHERE COALESCE( s_first, s_last ) IS NOT NULL AND F_ID < 100
GROUP BY F_ID 
ORDER BY F_ID ASC