0

I'm creating a SQL database for movies and I want to print out the number of movies that are Sci-Fi in the database.

I have ran this command, but I'm getting an error. Can anyone please points out to what is wrong in the command?

SELECT COUNT Genre FROM Movies WHERE Genre='Sci-Fi'

enter image description here

Ahmed Al Abdulaal
  • 270
  • 1
  • 3
  • 16

5 Answers5

3

count is a function, so you need to call it with an argument list in (). count, specifically, can get a special argument *, which means it will just count all the rows (that pass the filtering):

SELECT COUNT(*) FROM Movies WHERE Genre = 'Sci-Fi'
-- Here ----^

Additionally, since you genre column doesn't contain single values (a decision you may want to revisit), using the = operator like this will miss any movie that has multiple genres. Using like should do the trick:

SELECT COUNT(*) FROM Movies WHERE Genre LIKE '%Sci-Fi%'
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0
SELECT COUNT(Title) FROM Movies WHERE Genre like '%Sci-Fi%'
Mohammad
  • 132
  • 5
  • 1
    You answer is partial, you will miss records such as MoveiID=8 – ehh Mar 08 '17 at 06:55
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Donald Duck Mar 08 '17 at 11:24
0

Use below query

select count(*) from movies where Genre like "%Sci-Fi%"
Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
-1

SELECT COUNT(*) FROM Movies WHERE Genre like '%Sci-Fi%'

Vikram Singh
  • 924
  • 1
  • 9
  • 23
-2

Try this one: SELECT COUNT(*) FROM Movies WHERE Genre like 'Sci-Fi'

Kula
  • 25
  • 6