Find all sales from Jakarta in 2022
select sum(sales)
from table
where city = “Jakarta” and extract(year from date) = 2022
Correct. The query will find all sales from Jakarta in 2022 by filtering the table based on the conditions of city (Jakarta) and date (2022), and summing up the sales values.
Open
Find all sales from Jakarta in 2022
select sum(sales)
from table
where city = “Jakarta”
The query will not answer the question perfectly. While it will find the sum of sales from Jakarta, it does not specify the year. Additionally, it will not limit the search to only sales in the year 2022. To answer the question accurately, the query should be adjusted to include the year 2022 as well:
SELECT SUM(sales)
FROM table
WHERE city = "Jakarta" AND year = 2022;
Open
Find all sales from Jakarta in 2022
select sum(sales)
from table
where city = “Jakarta” and date = 2022
It is incorrect. The query only filters by city and date, it does not specify the source of the sales data or the name of the table where the data is stored. In addition, it is missing the year in the date condition, and it is only calculating the sum of sales without specifying which sales to include. A possible correct query to answer the question would be:
SELECT SUM(amount)
FROM sales_table
WHERE city = 'Jakarta' AND year(date) = 2022;
This query specifies the name of the table where the sales data is stored (sales_table), filters by city and year of the date column, and calculates the sum of the amount column (assuming that the column containing the sales amount is named 'amount').
Open