2016-09-04 2 views
1

간단한 시나리오에서 데이터웨어 하우징을 다루는 유니 작업에서 약간의 수정을하고 있습니다. 데이터웨어 하우스는 학생은 다른 기간, 학기 및 전공에 근거한 컴퓨터 실습실을 사용합니다. 참고로 , 우리의 데이터웨어 하우스는 네 개의 원래 테이블에서 내장되어 있습니다 :'단일 그룹 그룹 함수가 아님'SQL에서 오류가 발생했습니다.

  • USELOG (log_date, log_time, Student_ID, 법) 부품/전체
  • 학생 (Student_ID, 성별, 유형, CLASS_ID, Major_Code)
  • 주요 (Major_name, Major_code) 주요 (Major_name, Major_code)
  • 클래스 (Class_description, CLASS_ID)

내가 두 가지 오류를 얻을, 나는 (내 생각)에서 해결할 하나 다른 하나는교사의 해결책이 있고 비슷한 그룹을 가지고 있기 때문에 나는 실수로 그룹을 만들 수는 없지만 내가 그 일을 어떻게했는지에 관해 다른 점이 있다고 생각합니다. 다음과 같이

어쨌든, 내 코드는 다음과 같습니다

Create table Period_DIM (
PeriodID number, 
PeriodDesc varchar2(15), 
begin_time date, 
end_time date); 

Create Table Semester_DIM(
SemesterID number, 
Semester_Desc varchar2(15), 
start_date date, 
end_date date); 

Create Table Major_DIM as Select * from major; 

Create Table class_dim as select * from class; 

--Populate Period_Dim 
Insert Into Period_DIM Values(1, 'Morning', To_date('06:01', 'HH24:MI'), To_date('12:00', 'HH24:MI')); 
Insert Into Period_DIM Values(2, 'Afternoon', To_date('12:01', 'HH24:MI'), To_date('18:00', 'HH24:MI')); 
Insert Into Period_DIM Values(3, 'Evening', To_date('18:01', 'HH24:MI'), To_date('06:00', 'HH24:MI')); 

--Populate Semester_DIM 
Insert Into Semester_DIM Values (1, 'Semester 1', To_date('01-Jan', 'DD-MON'), To_date('15-JUL', 'DD-MON')); 
Insert Into Semester_DIM Values (2, 'Semester 2', To_date('16-Jul', 'DD-MON'), To_date('31-DEC', 'DD-MON')); 

--Create Temp Fact Table 
Create table tempfacttable As Select u.LOG_DATE, u.LOG_TIME, u.STUDENT_ID, s.CLASS_ID, s.MAJOR_CODE 
From Uselog u, student s 
where u.STUDENT_ID = s.STUDENT_ID; 

--Add a timeID to each row in the table because the data doesn't originally have them 
alter table tempfacttable add (timeid number); 
update tempfacttable 
set timeid = 1 
where to_char(log_time, 'HH24:MI') >= '06:01' 
and to_char(log_time, 'HH24:MI') <= '12:00'; 

update tempfacttable 
set timeid = 2 
where to_char(log_time, 'HH24:MI') >= '12:01' 
and to_char(log_time, 'HH24:MI') <= '18:00'; 

--Use OR in this case 
update tempfacttable 
set timeid = 3 
where to_char(log_time, 'HH24:MI') >= '18:00'or to_char (log_time, 'HH24:MI') <= '06:00'; 

--Add a semester ID based on the date in the tempfact cause its not contained in the Dimensions 
alter table tempfacttable add (semid varchar2(10)); 
update tempfacttable 
set semid= 'S1' 
where to_char(log_date, 'MMDD') >= '0101' 
and to_char(log_date, 'MMDD') <= '0715'; 

update tempfacttable 
set semid = 'S2' 
where to_char(log_date, 'MMDD') >= '0716' 
and to_char(log_date, 'MMDD') <= '1231'; 

--Create the Fact Table 
Create table factTable as 
select t.SEMID, t.TIMEID, t.MAJOR_CODE, t.CLASS_ID, count(t.student_id) as total_usage 
From tempfacttable t 
group by t.semid, t.timeid, t.class_id, t.major_code; 

select total_usage from tempfacttable; --returns error saying total_usage is an invalid operator 

--Usage for time period by major and by student's class 
--Select t.timeid, p.perioddesc, m.major_code, m.major_name, c.class_id, c.class_description, sum(t.total_usage) as usage_numbers 
--Previous line returns error because of t.total_usage, workaround is in the next line 
Select t.timeid, p.PERIODDESC, m.MAJOR_CODE, m.MAJOR_NAME, c.CLASS_ID, c.CLASS_DESCRIPTION, sum(count(t.student_id)) as usage_numbers 
from tempfacttable t, period_dim p, class_dim c, major_dim m 
where t.timeid = p.PERIODID 
and t.major_code = m.major_code 
group by t.timeid, p.PERIODDESC, t.major_code, m.major_name, t.class_id, c.class_description; 

내가이 작업을 얻이 수없는 것, 내가 그 '가 아닌 하나의 그룹 그룹 기능'라는 오류가 발생합니다. 나는 이것에 대한 도움과 왜 total_usage를 참조 할 수 없는지에 대한 이유에 대해 감사 할 것이다. 비록 그것을 포함하는 테이블에서 *를 선택하면 나머지 속성들과 함께 표시된다. 고마워요

+1

그냥 눈 - 볼링 하단에'SELECT' 문을 ... 당신의'GROUP BY' 문이 찾고 't.major_code' (t)에 대해서'm.MAJOR_CODE' (m)를 선택하고 있습니다. 나는 당신들이 그들이 동일해야한다고 말하는 절을 알고 있습니다. 그러나 당신은 일반적으로 당신이'선택 '하고있는 데이터를'GROUP'하고 싶습니다. 그것이 오라클이 화를 내고있는 것인지 궁금해합니다. – doublesidedstickytape

답변

1

tempfacttable에 정의 된 total_usage 열이 없기 때문입니다. 당신은, 그러나,

대신이 시도하여 factTable 테이블의 열 total_usage이 있습니까 :

select total_usage from factTable; 
관련 문제