For the following questions, use the NJ table . For these
questions. In some cases, the correct output is provided.
1. Write a query to return the rows of NJ where the name is Michael
and the birth year is in the 1990's (1990 through 1999). The
results should be in order by Sex, then Year. This is the correct
output:
State Sex Year Name N
----- ---- ----------- --------------- -----------
NJ F 1990 Michael 8
NJ F 1994 Michael 7
NJ F 1998 Michael 5
NJ M 1990 Michael 2875
NJ M 1991 Michael 2669
NJ M 1992 Michael 2531
NJ M 1993 Michael 2258
NJ M 1994 Michael 2059
NJ M 1995 Michael 1989
NJ M 1996 Michael 1737
NJ M 1997 Michael 1750
NJ M 1998 Michael 1725
NJ M 1999 Michael 1620
*/
HERE IS THE QUERY:
SELECT sex, year FROM `NJ`
WHERE name='Michael' AND year>=1990 AND year<=1999
ORDER BY sex, year
OR, IF YOU WANT ALL COLUMNS:
SELECT * FROM `table 1` WHERE name='Michael' AND year>=1990 AND year<=1999 ORDER BY sex, year
It uses a where condition with check of name and along with the AND operator to check the range of the date falls into 1990 to 1999. It produces the following output:
Get Answers For Free
Most questions answered within 1 hours.