w3resource
SQL exercises

SQL Exercises: Count the number of different non NULL city values for salesmen

SQL Aggregate Functions: Exercise-19 with Solution

Write a SQL statement that count the number of salesmen for whom a city is specified. Note that there may be spaces or no spaces in the city column if no city is specified.

Sample table: salesman


Sample Solution :

SELECT COUNT(*) 
FROM salesman 
WHERE city IS NOT NULL;

Output of the Query:

count
6

Explanation :

Syntax of counts the number of different non NULL city values for salesmen

Pictorial presentation:

Result of counts the number of different non NULL city values for salesmen

Query Visualization:

Duration:

Query visualization of Count the number of different non NULL city values for salesmen - Duration

Rows:

Query visualization of Count the number of different non NULL city values for salesmen - Rows

Cost:

Query visualization of Count the number of different non NULL city values for salesmen - Cost

Note: The pictorial represetation above is based on hypothetical table for the purpose of explanation only. Your answer may not match.

 

Practice Online


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a SQL statement that counts all orders for a date August 17th, 2012.
Next: Write a query that counts the number of salesmen with their order date and ID registering orders for each day.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming