0

我只是在我的 SQL 作业中遇到了问题。

我必须在我的数据中列出所有收入超过 3000.00 美元的员工。

这些是我的桌子

 EMPLOYEE Table  
    EMP_NUM EMP_NAME                JOB_CLASS  
        101 John G. News            Database Designer
        102 David H. Senior         Systems Analyst
        103 June E. Arbough         Electrical Engineer
        104 Anne K. Ramoras         Systems Analyst
        105 Alice K. Johnson        Database Designer
        106 William Smithfield      Programmer
        107 Maria D. Alonzo         Programmer
        108 Ralph B. Washington     Systems Analyst
        111 Geoff B. Wabash         Clerical Support
        112 Darlene M. Smithson     DSS Analyst
        113 Delbert K. Joenbrood    Applications Designer
        114 Annelise Jones          Applications Designer
        115 Travis B. Bawangi       Systems Analyst
        118 James J. Frommer        General Support

ASSIGN Table
EMP_NUM  PROJ_NUM  HOURS
101      15        19.4
102      15        23.8
103      15        23.8
105      15        35.7
106      15        12.6
104      18        32.4
112      18        44
114      18        24.6
118      18        45.3
104      22        48.4
105      22        64.7
106      22        12.8
111      22        22
113      22        23.6
101      25        56.3
107      25        24.6
108      25        23.6
112      25        41.4
114      25        33.1
115      25        45.8
118      25        30.5

JOB Table
JOB_CLASS               CHG_HOUR
Applications Designer   48.1
Clerical Support        26.87
Database Designer       105
DSS Analyst             45.95
Electrical Engineer     84.5
General Support         18.36
Programmer              35.75
Systems Analyst         96.75

对于上一个列出所有从事多个项目的员工的问题,我确实喜欢这个

select COUNT (a.PROJ_NUM), e.EMP_NAME
from EMPLOYEE e, ASSIGN a
where e.EMP_NUM = a.EMP_NUM
Having COUNT (a.PROJ_NUM) >= 2
group by e.EMP_NAME;

这段代码给了我我想要的

我现在遇到的麻烦是获取收入超过 3000.00 的列表

所以我确实喜欢这个

select COUNT (a.HOURS * j.CHG_OUR), e.EMP_NAME
from EMPLOYEE e, ASSIGN a. JOB j
where j.JOB_CLASS = e.JOB_CLASS
and e.EMP_NUM = a.EMP_NUM
Having COUNT (a.HOURS * j.CHG_OUR) >= 3000
group by e.EMP_NAME;

但是这一次,这段代码没有给我想要的

它只打印出这样的错误消息

ORA-00933: SQL command not properly ended
00933. 00000 -  "SQL command not properly ended"
*Cause:    
*Action:
Error at Line: 60 Column: 26

如果您知道如何解决它,请回答我

谢谢

4

3 回答 3

1
  1. 您的 HAVING 语句必须出现在您的 GROUP BY 之后而不是之前。
  2. 你不想使用 COUNT() 聚合,你想要 SUM()。

像这样的东西:

 select SUM (a.HOURS * j.CHG_OUR), e.EMP_NAME
            from EMPLOYEE e, ASSIGN a. JOB j
            where j.JOB_CLASS = e.JOB_CLASS
            and e.EMP_NUM = a.EMP_NUM
            group by e.EMP_NAME
            Having SUM (a.HOURS * j.CHG_OUR) >= 3000;
于 2013-03-05T01:12:16.107 回答
0

我认为你可以这样做:

select SUM(a.HOURS * j.CHG_OUR), e.EMP_NAME
from EMPLOYEE e, ASSIGN a, JOB j
where j.JOB_CLASS = e.JOB_CLASS
and e.EMP_NUM = a.EMP_NUM
group by e.EMP_NAME
Having sum(a.HOURS * j.CHG_OUR) >= 3000;
于 2013-03-05T01:13:38.550 回答
0

那这个呢:

select COUNT (a.HOURS * j.CHG_OUR), e.EMP_NAME
from EMPLOYEE e, ASSIGN a. JOB j
where j.JOB_CLASS = e.JOB_CLASS
and e.EMP_NUM = a.EMP_NUM
group by e.EMP_NAME;
Having COUNT ((a.HOURS * j.CHG_OUR) >= 3000)

我在您的计数周围添加了一组额外的括号。

于 2013-03-05T01:25:20.530 回答