Question

The question is How many interviews were there in 1995 and 1996. You must use the IN keyword for your comparison. Also there is a function called YEAR() that will return the year portion of a date.

TABLE:

mysql> SELECT interviewdate "Date"
    -> FROM interview;    

+------------+
| Date       |
+------------+
| 1995-06-01 |
| 1995-06-01 |
| 1995-06-30 |
| 1995-06-30 |
| 1995-07-01 |
| 1995-08-01 |
| 1995-08-01 |
| 1995-08-02 |
| 1995-12-01 |
| 1995-12-02 |
| 1995-12-04 |
| 1996-01-21 |
| 1996-02-01 |
| 1996-02-02 |
| 1996-07-01 |
| 1996-07-01 |
| 1996-08-01 |
| 1996-08-08 |
| 1996-08-11 |
| 1997-01-01 |
| 1997-01-01 |
| 1997-01-31 |
| 1997-02-01 |
| 1997-03-24 |
| 1997-03-31 |
| 1997-04-20 |
| 1997-04-22 |
| 1997-05-01 |
+------------+
28 rows in set (0.00 sec)

OUTPUT:

The condition is to count only those with the Date of 1995 and 1996 into a new table AS "Count(*)". Does anyone know how to do this? I am new to mySQL and trying to understand the syntax. I tried something like this:

SELECT interviewdate, COUNT(interviewdate) AS "COUNT(*)"
FROM interview
GROUP BY interviewdate
HAVING COUNT(interviewdate) == 1995 AND 1996;


+----------+
| COUNT(*) |
+----------+
|       19 |
+----------+
1 row in set (0.00 sec)
Was it helpful?

Solution

This should work:

select count(*)
from interview
where year(interviewdate) in (1995,1996)

And if you need to insert the results into a new table, then use create table as -- more fiddle.

OTHER TIPS

Try:

SELECT COUNT(*) AS number FROM interview WHERE (interviewdate > 1995-12-31 AND interviewdate < 1997-01-01)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top