Maryam Masood
Maryam Masood

Reputation: 43

SQL query-Count(*) with a condition

So I am a beginner at SQL and I am stuck with this query: "For event requests, list the event number, event date (eventrequest.dateheld), and count of the event plans. Only include event requests in the result if the event request has more than one related event plan with a work date in December 2013."

The tables are:

EVENTREQUEST{EVENTNO(PK),DATEHELD}

EVENTPLAN{PLANO(PK), EVENTNO(FK), WORKDATE}

I have written this query so far but I dont know how to proceed, I mean how will we count the number of event plans with workdate in December 2013? Please help!

    Select EVENTNO, EVENTREQUEST.DATEHELD, COUNT(*) 
    from EVENTREQUEST, EVENTPLAN
    where EVENTREQUEST.EVENTNO = EVENTPLAN.EVENTNO;

Upvotes: 2

Views: 697

Answers (1)

Hedeshy
Hedeshy

Reputation: 1386

Here is what you need

SELECT COUNT(1) as PLANS, EVENTREQUEST.EVENTNO, DATEHELD
FROM EVENTREQUEST LEFT JOIN EVENTPLAN
ON EVENTREQUEST.EVENTNO = EVENTPLAN.EVENTNO
WHERE EVENTPLAN.WORKDATE BETWEEN '2015-11-30' AND '2015-12-30';

Upvotes: 2

Related Questions