SQLite Case Statements and Examples

Slide Note
Embed
Share

"Explore the versatile use of CASE statements in SQLite for conditional logic, decision-making, and data manipulation. Learn how to apply CASE syntax, create case statements for SELECT queries, and perform conditional updates. Discover real-world examples demonstrating CASE statement usage."


Uploaded on Aug 14, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. SQLite

  2. CASE Syntax CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 WHEN conditionN THEN resultN ELSE result END;

  3. Case Statement for SELECT SELECT orders_id, amount, CASE WHEN amount > 24 THEN 'The amount is greater than 25' WHEN amount = 22 THEN 'The amount is 22' ELSE 'The amount is under 22' END AS amountText FROM ORDERS;

  4. Example of Case Statement

  5. Case Statement for Conditional Updates Write the SQL statement by using case to The company want to give 10% discount for all orders amount with value greater than 30 JD and 5 % on amount under 30 JD only on 2/12/2022 Check by yourself how to make the discount first

  6. Example Write the SQL statement show that If employee earn over 5000 as salary then s\he is a boss If employee earn less than 5000 and over 4000 as salary then s\he is a manager If employee earn between 2000 and 1500 as salary then s\he is a worker Else he is trainee

  7. Table with Auto_Increment

  8. Rename Table To rename a table in SQLite, the following syntax is used.

  9. Table with Auto_Increment (insert)

  10. Data Types

  11. Data Types

  12. Example

  13. Data Types (typeof)

  14. Date and Time Data Type three special keywords that may be used as a default value: CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP.