我想运行一个查询,在那里我想找到 TICKETS
相同 EMPLOYEE
至少记录3次 ENTRY
但在这方面没有任何进展 TICKET
. 不幸的是,我在以下方面遇到了问题:
如何检查进度
TICKET ENTRY
有 ACTIVITY_ID
定义的活动是
INSERT INTO ACTIVITY(ACTIVITY_ID,ACTIVITY_NAME) VALUES ('RGSTR','REGISTER')
INSERT INTO ACTIVITY(ACTIVITY_ID,ACTIVITY_NAME) VALUES ('ASST','ASSISTANCE')
INSERT INTO ACTIVITY(ACTIVITY_ID,ACTIVITY_NAME) VALUES ('ADVTS','ADVERTISEMENT')
INSERT INTO ACTIVITY(ACTIVITY_ID,ACTIVITY_NAME) VALUES ('SALE','SALE')
INSERT INTO ACTIVITY(ACTIVITY_ID,ACTIVITY_NAME) VALUES ('RFND','REFUND')
INSERT INTO ACTIVITY(ACTIVITY_ID,ACTIVITY_NAME) VALUES ('EXTND','EXTEND')
到目前为止我所做的是:
SELECT
TICKET.TICKET_ID,
EMPLOYEE.LAST_NAME,
COUNT(TICKET.TICKET_ID) AS NUMBER
FROM ENTRY
JOIN EMPLOYEE ON ENTRY.EMPLOYEE_ID = EMPLOYEE.EMPLOYEE_ID
JOIN TICKET ON ENTRY.TICKET_ID = TICKET.TICKET_ID
GROUP BY TICKET.TICKET_ID, EMPLOYEE.LAST_NAME
HAVING COUNT(ENTRY.ACTIVITY_ID) >= 3
我选择了一些列来查看输出是什么(当我有一个 SELECT COUNT(*)
输出是两行,两行都是3行。这是数钱 ENTRY
每一张票,但我要数 TICKET
大于等于3的 ENTRY
以及上述额外财产)
ID LAST_NAME NUMBER No Column Name
5 LaBeouf 3 3
6 Musk 3 3
这个输出没有错,因为我在 ENTRY
下表类似,但我基本上想得到这个输出中的行数,但做不到。
--more entries above
--.
--.
INSERT INTO ENTRY(ACTIVITY_ID,EMPLOYEE_ID,TICKET_ID,DATE,DESCRIPTION)
VALUES ('RGSTR',6,5,'2020-5-29','Didnt do anything')
INSERT INTO ENTRY(ACTIVITY_ID,EMPLOYEE_ID,TICKET_ID,DATE,DESCRIPTION)
VALUES ('RGSTR',6,5,'2020-5-29','Didnt do anything')
INSERT INTO ENTRY(ACTIVITY_ID,EMPLOYEE_ID,TICKET_ID,DATE,DESCRIPTION)
VALUES ('RGSTR',6,5,'2020-5-29','Didnt do anything')
INSERT INTO ENTRY(ACTIVITY_ID,EMPLOYEE_ID,TICKET_ID,DATE,DESCRIPTION)
VALUES ('RGSTR',2,6,'2020-5-29','Didnt do anything')
INSERT INTO ENTRY(ACTIVITY_ID,EMPLOYEE_ID,TICKET_ID,DATE,DESCRIPTION)
VALUES ('RGSTR',2,6,'2020-5-29','Didnt do anything')
INSERT INTO ENTRY(ACTIVITY_ID,EMPLOYEE_ID,TICKET_ID,DATE,DESCRIPTION)
VALUES ('RGSTR',2,6,'2020-5-29','Didnt do anything')
最后,我自己设计了数据库作为项目的一部分这里是er图,如果它能帮助你更好地理解。
感谢所有花时间帮忙的人
edit:解决了这个问题,我基本上计算了上面输出中的行数,并添加了一个where语句,它将只计算 ENTRY
ies与 ACTIVITY_ID='RGSTR'
```
SELECT COUNT() AS # FROM
(SELECT
TICKET.TICKET_ID,
EMPLOYEE.LAST_NAME,COUNT() AS NUMBER FROM ACTIVITY
INNER JOIN ENTRY ON ACTIVITY.ACTIVITY_ID = ENTRY.ACTIVITY_ID
INNER JOIN EMPLOYEE ON ENTRY.EMPLOYEE_ID = EMPLOYEE.EMPLOYEE_ID
INNER JOIN TICKET ON ENTRY.TICKET_ID = TICKET.TICKET_ID
WHERE ENTRY.ACTIVITY_ID = 'RGSTR'
--added above line since we are checking
--for tickets that an employe worked >=3 times but couldn't resolve
GROUP BY TICKET.TICKET_ID,EMPLOYEE.LAST_NAME
HAVING COUNT(ENTRY.ACTIVITY_ID) >= 3) c
我应该删除这个线程吗?
暂无答案!
目前还没有任何答案,快来回答吧!