user2881231
user2881231

Reputation: 21

is it possible to do this in SQL?

MEMBERS TABLE:

 ID Resident    Gender      Location

1   Steve       M       S-55
2   Roger       M       S-42
3   Martha      F       R-20
4   Samantha    F       CC
5   Tom         M       S-12

I am trying to code an SQL Statement that returns a single numerical value.

Something along the lines of:

SELECT COUNT(Gender) 
FROM Members
WHERE GENDER = M 
   AND Location CONTAINS 'S%'

The AND LOCATION obviously doesn't really exist in SQL in that syntax, but I'm hoping to get the count of how many members that are MALE and reside in a location that has an S in it.

Is this possible?

Upvotes: 1

Views: 75

Answers (2)

Ruslan K.
Ruslan K.

Reputation: 1981

SELECT COUNT(*) as count
FROM Members
WHERE GENDER = 'M' AND Location LIKE 'S%'

Upvotes: 1

Squirrel
Squirrel

Reputation: 24803

SELECT COUNT(*)
FROM   Members
WHERE  GENDER = 'M'
AND    Location LIKE '%S%'

Upvotes: 2

Related Questions