Featured Post

Python map() and lambda() Use Cases and Examples

Image
 In Python, map() and lambda functions are often used together for functional programming. Here are some examples to illustrate how they work. Python map and lambda top use cases 1. Using map() with lambda The map() function applies a given function to all items in an iterable (like a list) and returns a map object (which can be converted to a list). Example: Doubling Numbers numbers = [ 1 , 2 , 3 , 4 , 5 ] doubled = list ( map ( lambda x: x * 2 , numbers)) print (doubled) # Output: [2, 4, 6, 8, 10] 2. Using map() to Convert Data Types Example: Converting Strings to Integers string_numbers = [ "1" , "2" , "3" , "4" , "5" ] integers = list ( map ( lambda x: int (x), string_numbers)) print (integers) # Output: [1, 2, 3, 4, 5] 3. Using map() with Multiple Iterables You can also use map() with more than one iterable. The lambda function can take multiple arguments. Example: Adding Two Lists Element-wise list1 = [ 1 , 2 , 3 ]

3 SQL Query Examples to Create Views Quickly

There are three kinds of Views in SQL. The three views are Read-only, Force, and Updatable. Views real usage is to hide data. And you need to ensure base tables are present before you create a View.


You can call views as logical tables. The advantage of Views is you can show only some of the fields of base tables.


What is a View in SQL
  • A view can be constructed with another view so it is called a nested view.
  • You can create or replace an existing view
  • A view can be created without having base tables. This is possible with the FORCE option.
#1: Read-Only Views

The standard syntax for the view is as follows:

CREATE OR replace VIEW invoice_summary AS
SELECT vendor_name count(*) AS invoice_count,
SUM(invoice_total) AS invoice_total_sum
FROM vendor
JOIN invoices
ON vendors.vendor_id*invoices.vendor_id
GROUP BY vendor_name;

Notes: You cannot update Read-only Views


#2: Force Views

CREATE FORCE VIEW products_list
AS
SELECT product_description,
product_price
FROM products;

Notes: Without base Table you can create a FORCE View.


#3: Updatable Views

A view can be updatable if a view follows certain rules.

A view when it is created for update purpose, you can give INSERT, UPDATE and DELETE operations.

A read-only view should contain WITH  READ ONLY clause

While updating a view, it is possible to update only one base table at a time. When you created a view from more than one table, then it is not possible to update two tables at a time.


How to Manipulate Views 

ALTER View

  • CREATE OR REPLACE statement you can use to ALTER the View.

Drop View

  • Drop view vendor_sw

Summary

A view with CHECK OPTION restricts to update. When condition satisfied it updates.

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

SQL Query: 3 Methods for Calculating Cumulative SUM

Python placeholder '_' Perfect Way to Use it