Question
Given the following tables: Orders (OrderID,
CustomerID, OrderDate) and Customers (CustomerID, CustomerName, City), what SQL query will return the names of customers who have placed orders in 'New York' within the last 30 days?Solution
The correct query utilizes a JOIN between the Customers and Orders tables on the CustomerID field. This allows you to filter customers who are located in 'New York' and have placed an order in the last 30 days. The JOIN ensures that only customers who have an associated order are included, and the date condition (OrderDate >= CURDATE() - INTERVAL 30 DAY) filters for recent orders. Why Other Options Are Wrong : A) Incorrect : The query attempts to filter customers directly, but it fails to include the necessary JOIN with the Orders table, which is crucial for retrieving orders placed by customers in 'New York'. C) Incorrect : This query incorrectly selects from the Orders table and does not filter by customer details. The City column does not exist in the Orders table. D) Incorrect : This query incorrectly attempts to select data from the Customers table without joining it with the Orders table, so there will be no filtering by order date. E) Incorrect : Although the JOIN is correctly applied, this query places the conditions in the wrong order, and the query logic would still be correct but unnecessarily complex.
βCβ and βDβ started a business by investing Rs. 30,000 and Rs. 25,000, respectively. βDβ manages the business and for that he is entitled to...
A, B and C hired a taxi for Rs. 810 and used it for 2, 3, 4 hours respectively. Hiring charges paid by B are:
βAβ, βBβ and βCβ started a business by investing Rs. 4,000, Rs. 4,800 and Rs. 3,200, respectively. After 6 months, βBβ decreased his inv...
A started a retail business by investing Rs.40,000. After eight months B joined him with a capital ofΒ Rs.80,000. After 2 years, they earned a profit of...
A, B and C invest in a partnership in the ratio 8:5:10 and investment of A is Rs.200 less than investment of C. Partner B invests for 1/5th and A and C ...
Aβ, βBβ and βCβ started a business by investing Rs. 8,000, Rs. 9,500, and Rs. 7,500, respectively such that βBβ invested for 2 months more...
A and B together start a business with investment of Rs. 1600 and Rs. (x + 600), respectively. If the profit earned after 5 years is Rs. 6000 and share ...
M and N started a business by investing Rs.5000 and Rs.6000 respectively. After 6 months, M and N increased their investments by 40% and Rs.2000 respect...
The investments of A and B in a partnership are Rs. 6000 and Rs. 10000. B withdraws 40% of initial investment after T months. If annual profit is Rs. 70...
A, B and C invested in partnership. A invest Rs.6000 for 4 months, B invests Rs.4000 for 3 months and C invests Rs.12000 for 2 months. C is working part...