SQL query to find the number of users who have both a first and last name

This technical problem deals with writing a SQL query to find the number of users who have both a first and last name. The input is a table of user data, and the output is the number of users who have both a first and last name.

Problem

Given a table of user data, write a SQL query to find the number of users who have both a first and last name.
Example input:
| first_name | last_name |
|------------|-----------|
| John       | Smith     |
| Jane       | Doe       |
| NULL       | Doe       |
| NULL       | Smith     |
Example output:
| num_users  |
|------------|
| 2          |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT COUNT(*) AS num_users
FROM users
WHERE first_name IS NOT NULL AND last_name IS NOT NULL;

/*

The solution above is optimal because it only counts the number of users who have both a first and last name.

*/

A.I. Evaluation of the Solution

The solution above is correct and demonstrates a level of completeness. It solves the problem and takes the optimal approach by only counting the number of users who have both a first and last name.

Evaluated at: 2022-11-17 23:34:49