我有以下 SQL 代码:
SELECT ACTIVITY_TYPE, COUNT(EVENT_ID) as etv, SUM(etv) as etva, AVG(etva)
FROM ACTIVITIES, "EVENTS"
WHERE ACTIVITIES.ACTIVITY_ID="EVENTS".ACTIVITY_ID
GROUP BY ACTIVITY_TYPE;
这是试图回答这个问题:
d) 提供有关所提供的各种活动类型的管理信息的查询。对于每种类型的活动,查询应显示参加该类型活动的总人数以及参加每种活动的平均人数。
不幸的是,我收到以下错误:
ORA-00904: "ETVA": invalid identifier
任何帮助都会很棒!
编辑:
SELECT ACTIVITY_TYPE, COUNT(EVENT_ID), AVG(COUNT(EVENT_ID))
FROM ACTIVITIES, "EVENTS"
WHERE ACTIVITIES.ACTIVITY_ID="EVENTS".ACTIVITY_ID
GROUP BY ACTIVITY_TYPE;
这是我现在收到此错误的新查询:
ORA-00937: not a single-group group function
表结构:
CREATE TABLE "GROUPS" (
GROUP_ID NUMBER( 4 ) NOT NULL CONSTRAINT GROUP_ID_PK PRIMARY KEY ,
GROUP_NAME VARCHAR2(35) NULL,
GROUP_NUMBER_OF_MEMBERS NUMBER( 3 ) NOT NULL ,
GROUP_LEADER_ID NUMBER( 4 ) NOT NULL
);
CREATE TABLE MEMBERS (
MEMBER_ID NUMBER( 4 ) NOT NULL CONSTRAINT MEMBER_ID_PK PRIMARY KEY ,
MEMBER_SURNAME VARCHAR2( 35 ) NOT NULL ,
MEMBER_FIRST_NAME VARCHAR2( 35 ) NOT NULL ,
MEMBER_DOB DATE NOT NULL ,
MEMBER_GENDER VARCHAR2( 1 ) NOT NULL CONSTRAINT MEMBER_GENDER_CHECK CHECK ( MEMBER_GENDER IN ( 'M' , 'F' ) ),
GROUP_ID NUMBER( 4 ) NOT NULL,
CONSTRAINT GROUP_ID_FK_MEMBER FOREIGN KEY (GROUP_ID) REFERENCES "GROUPS"(GROUP_ID)
);
CREATE TABLE CHALETS (
CHALET_NO NUMBER( 4 ) NOT NULL CONSTRAINT CHALET_ID_PK PRIMARY KEY ,
CHALET_NAME VARCHAR2( 35 ) NOT NULL,
CHALET_CAPACITY NUMBER( 2 ) NOT NULL,
CHALET_RATE NUMBER( 6 , 2 ) NOT NULL
);
CREATE TABLE SUPERVISORS (
SUPERVISOR_ID NUMBER ( 4 ) NOT NULL CONSTRAINT SUPERVISOR_ID_PK PRIMARY KEY ,
SUPERVISOR_SURNAME VARCHAR2( 35 ) NOT NULL ,
SUPERVISOR_FIRST_NAME VARCHAR2( 35 ) NOT NULL ,
SUPERVISOR_MOBILE_NUMBER VARCHAR2( 11 ) NOT NULL
);
CREATE TABLE ACTIVITIES (
ACTIVITY_ID NUMBER ( 4 ) NOT NULL CONSTRAINT ACTIVITY_ID_PK PRIMARY KEY ,
ACTIVITY_TYPE VARCHAR ( 35 ) NOT NULL ,
ACTIVITY_TITLE VARCHAR2( 35 ) NOT NULL
);
CREATE TABLE BOOKINGS (
BOOKING_ID NUMBER( 4 ) NOT NULL CONSTRAINT BOOKING_ID_PK PRIMARY KEY ,
GROUP_ID NUMBER( 4 ) NOT NULL ,
CHALET_ID NUMBER( 4 ) NOT NULL ,
BOOKING_START_DATE DATE NOT NULL ,
BOOKING_END_DATE DATE NOT NULL ,
CONSTRAINT GROUP_ID_FK_BOOKING FOREIGN KEY (GROUP_ID) REFERENCES GROUPS(GROUP_ID) ,
CONSTRAINT CHALET_ID_FK_BOOKING FOREIGN KEY (CHALET_ID) REFERENCES CHALETS(CHALET_NO)
);
CREATE TABLE "EVENTS" (
EVENT_ID NUMBER ( 4 ) NOT NULL CONSTRAINT EVENT_ID_PK PRIMARY KEY ,
MEMBER_ID NUMBER ( 4 ) NOT NULL ,
SUPERVISOR_ID NUMBER ( 4 ) NOT NULL ,
ACTIVITY_ID NUMBER ( 4 ) NOT NULL ,
EVENT_COMMENTS VARCHAR2( 500 ) ,
EVENT_DATE DATE NOT NULL ,
EVENT_TIME_SLOT VARCHAR2( 2 ) NOT NULL ,
CONSTRAINT MEMBER_ID_FK_EVENT FOREIGN KEY (MEMBER_ID) REFERENCES MEMBERS(MEMBER_ID) ,
CONSTRAINT SUPERVISOR_ID_FK_EVENT FOREIGN KEY (SUPERVISOR_ID) REFERENCES SUPERVISORS(SUPERVISOR_ID) ,
CONSTRAINT ACTIVITY_ID_FK_EVENT FOREIGN KEY (ACTIVITY_ID) REFERENCES ACTIVITIES(ACTIVITY_ID)
);
ALTER TABLE "GROUPS" ADD CONSTRAINT MEMBER_ID_FK_GROUP_LEADER FOREIGN KEY (GROUP_LEADER_ID) REFERENCES MEMBERS(MEMBER_ID);