我正在使用oracle 10g designer和sqlplus开发数据库系统 我必须创建多个查询,大多数都很容易,但有一些我遇到了一些问题。
我在这里有一个查询,当运行返回204行数据时,它实际上应该返回17行数据。这些行似乎重复了12次。我无法绕过这个;已经过了好几个小时。我正在提交我的代码,查询应该如何查看的截图(scs表单),我的ERD,结果的屏幕截图和解释计划表输出。重复行是最后10列的结果。
有人可以帮忙吗?
COLUMN C_FNAME FORMAT A10
COLUMN C_LNAME FORMAT A10
COLUMN C_ORG FORMAT A35
COLUMN C_ADR FORMAT A35
COLUMN C_CNUM FORMAT 9999999
COLUMN E_ID FORMAT A7
COLUMN E_NAME FORMAT A35
COLUMN E_FTIME FORMAT A21
COLUMN E_STIME FORMAT A21
COLUMN ET_DESC FORMAT 10
COLUMN V_NAME FORMAT A30
COLUMN V_ADDRESS FORMAT A35
COLUMN V_CNUM FORMAT 9999999
COLUMN D_DESC FORMAT A30
COLUMN D_AMT FORMAT A3
COLUMN ST_DESC FORMAT A15
COLUMN S_FNAME FORMAT A15
COLUMN S_LNAME FORMAT A15
COLUMN EQ_TYPE FORMAT A15
COLUMN EQ_DESC FORMAT A15
COLUMN EQ_AMT FORMAT A3
COLUMN SU_NAME FORMAT A40
BREAK ON C_FNAME ON C_LNAME ON C_ORG ON C_ADR ON C_CNUM ON E_ID ON E_NAME ON E_STIME ON E_FTIME ON ET_DESC ON V_NAME ON V_ADDRESS ON V_CNUM ON D_DESC ON D_AMT ON EQ_TYPE ON EQ_DESC ON EQ_AMT ON SU_NAME
SELECT C_FNAME, C_LNAME, C_ORG, C_ADR, C_CNUM, E_ID, E_NAME, E_FTIME, E_STIME, ET_DESC, V_NAME, V_ADDRESS, V_CNUM, D_DESC, D_AMT, ST_DESC, S_FNAME, S_LNAME, EQ_TYPE, EQ_DESC, EQ_AMT, SU_NAME
FROM CUSTOMER, EVENTTYPE, STAFFTYPE, VENUE, EVENT, STAFF, EVENT_DISHES, EVENT_EQUIPMENT, EVENT_STAFF, DISHES, EQUIPMENT, SUPPLIER
WHERE E_ID ='E000001'
AND CUSTOMER.C_ID = EVENT.C_C_ID
AND EVENTTYPE.ET_ID = EVENT.ET_ET_ID
AND VENUE.V_ID = EVENT.V_V_ID
AND EVENT_DISHES.E_E_ID = EVENT.E_ID
AND EVENT_DISHES.D_D_ID = DISHES.D_ID
AND EVENT_EQUIPMENT.E_E_ID = EVENT.E_ID
AND EVENT_EQUIPMENT.EQ_EQ_ID = EQUIPMENT.EQ_ID
AND EQUIPMENT.SU_SU_ID = SUPPLIER.SU_ID
AND EVENT_STAFF.E_E_ID = EVENT.E_ID
AND EVENT_STAFF.S_S_ID = STAFF.S_ID
AND STAFF.ST_ST_ID = STAFFTYPE.ST_ID;
答案 0 :(得分:2)
返回的204行是查询产生的正确数量。 您有17名员工个人(其类型仅来自)。这17行乘以2个盘子并乘以2个雇佣和4个所需(2 + 4 = 6)设备。所以17 * 2 * 6给你204行。
这是因为例如查询EVENT_DISHES以填充17到目前为止的现有行,其结果与给定的E_ID匹配,并且每次返回2 d_d_id。
我认为您的目标是创建以编程方式提供的表单。要实现此目的,您需要四次查询数据库。一次为活动本身,一次为菜肴,一次为设备,一次为与活动相关的工作人员。
SELECT C_FNAME, C_LNAME, C_ORG, C_ADR, C_CNUM, E_ID, E_NAME, E_FTIME, E_STIME, ET_DESC, V_NAME, V_ADDRESS, V_CNUM
FROM event
INNER JOIN customer ON EVENT.C_C_ID = CUSTOMER.C_ID
INNER JOIN eventtype ON EVENT.ET_ET_ID = EVENTTYPE.ET_ID
INNER JOIN venue ON EVENT.V_V_ID = VENUE.V_ID
WHERE E_ID ='E000001';
SELECT D_DESC, D_AMT
FROM EVENT_DISHES
INNER JOIN DISHES ON DISHES.D_ID = EVENT_DISHES.D_D_ID
WHERE E_E_ID ='E000001';
SELECT EQ_TYPE, EQ_DESC, EQ_AMT, SU_NAME
FROM EVENT_EQUIPMENT
INNER JOIN EQUIPMENT ON EVENT_EQUIPMENT.EQ_EQ_ID = EQUIPMENT.EQ_ID
INNER JOIN SUPPLIER ON SUPPLIER.SU_ID = EQUIPMENT.SU_SU_ID
WHERE E_E_ID ='E000001';
SELECT ST_DESC, S_FNAME, S_LNAME
FROM EVENT_STAFF
INNER JOIN STAFF ON STAFF.S_ID = EVENT_STAFF.S_S_ID
INNER JOIN STAFFTYPE ON STAFFTYPE.ST_ID = STAFF.ST_ST_ID
WHERE E_E_ID ='E000001';
我希望我将所有字段正确匹配到相应的查询。根据需要进行修改。
答案 1 :(得分:0)
如果重构查询以使用ANSI兼容的连接语法而不是WHERE子句中的=,则可能更容易。
SELECT C_FNAME, C_LNAME, C_ORG, C_ADR, C_CNUM, E_ID, E_NAME, E_FTIME, E_STIME, ET_DESC, V_NAME, V_ADDRESS, V_CNUM, D_DESC, D_AMT, ST_DESC, S_FNAME, S_LNAME, EQ_TYPE, EQ_DESC, EQ_AMT, SU_NAME
FROM customer
INNER JOIN event ON CUSTOMER.C_ID = EVENT.C_C_ID
INNER JOIN eventtype ON EVENT.ET_ET_ID = EVENTTYPE.ET_ID
INNER JOIN venue ON EVENT.V_V_ID = VENUE.V_ID
INNER JOIN EVENT_DISHES ON EVENT.E_ID = EVENT_DISHES.E_E_ID
INNER JOIN DISHES ON DISHES.D_ID = EVENT_DISHES.D_D_ID
INNER JOIN EVENT_EQUIPMENT ON EVENT.E_ID = EVENT_EQUIPMENT.E_E_ID
INNER JOIN EQUIPMENT ON EVENT_EQUIPMENT.EQ_EQ_ID = EQUIPMENT.EQ_ID
INNER JOIN SUPPLIER ON SUPPLIER.SU_ID = EQUIPMENT.SU_SU_ID
INNER JOIN EVENT_STAFF ON EVENT.E_ID = EVENT_STAFF.E_E_ID
INNER JOIN STAFF ON STAFF.S_ID = EVENT_STAFF.S_S_ID
INNER JOIN STAFFTYPE ON STAFFTYPE.ST_ID = STAFF.ST_ST_ID
WHERE E_ID ='E000001';
我正在调查您的数据现在不正确的原因,但这是一个可以开始的地方。
我认为在加入event_equipment和供应商表时存在问题。该表中的数据是唯一的吗?