Write a SQL query to find the number of rows where the value in the second...

Given a table with two columns, this SQL query will find the number of rows where the value in the second column is greater than the value in the first column.

Problem

Given a table of data with two columns, write a SQL query to find the number of rows where the value in the second column is greater than the value in the first column.
Input:
| Column 1 | Column 2 |
|----------|----------|
| 1        | 3        |
| 2        | 4        |
| 3        | 2        |
| 4        | 1        |
Output:
3

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT COUNT(*)
FROM table
WHERE column2 > column1;

/*

The above solution is optimal because it uses a single query to find the number of rows where the value in the second column is greater than the value in the first column.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and uses an optimal approach.

Evaluated at: 2022-11-12 10:15:29