![]() For any other rental_rate, only include films whose rental_duration is equal to 6.When the rental_rate is equal to 4.99, only include films whose rental_duration is equal to 5.When the rental_rate is equal to 2.99, only include films whose rental_duration is equal to 4.When the rental_rate is equal to 0.99, only include films whose rental_duration is equal to 3.That has the effect of associating rental_rates with the rental_durations. We could do that using a Case Statement like so: For instance, let's suppose that we wanted to set the rental_duration based on the rental_rate. SELECT film_id, title, rental_rate, rental_durationĮxecuting the query in Navicat Premium brings up the following results: Setting Rental Duration Based On Rental RateĪ Case Statement comes in handy for choosing a value based on several other possible values. Our query displays the film id, title, rental rate, and a rental duration columns and narrows down the field to those films whose rental_duration is exactly 5 days. ![]() Tables include actor, film, customer, rentals, etc.by film id, title, rental rate, and a rental duration of 5 days. It's a MySQL database that contains a number of tables, views, and queries related to a fictional video rental store. ![]() Listing Films by Rental Durationīefore getting to the CASE Statement, let's start with a query that returns a list of movies from the from the Sakila Sample Database. In today's blog, we'll create a SELECT query in Navicat Premium that returns rows based on the values of another field. Within that context, the Case Statement is ideally suited to both static queries, as well as dynamic ones, such as those that you would find inside a stored procedure. There, it may be utilized to alter the data fetched by a query based on a condition. Another way to use the Case Statement is within the WHERE clause. In that blog, we employed the Case Statement as most DBAs and developers do, in the SELECT clause. Using a Case Statement in a Where Clause by Robert GravelleĪ short time ago we were introduced the incredibly useful and versatile Case Statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |