SQL4
SQL4
--Use Database
Use Customer;
--Displaying the table with Condition(Select only the �first_name� & �last_name�
columns from the customer table & Select those records where �first_name� starts
with �G� and city is �San Jose)
Select * from Customer_Details;
Select Customer_First_Name,Customer_Last_Name from Customer_Details;
Select * from Customer_Details where Customer_First_Name like 'G%' and
Customer_City like 'San Jose';
-- Make an inner join on �Customer� & �Order� tables on the �customer_id� column
select c.*,o.* from Customer_Details as c
Inner join
Orders as o
on c.Customer_ID=o.Customer_ID;
--Make left and right joins on �Customer� & �Order� tables on the �customer_id�
column
select c.*,o.* from Customer_Details as c
Right join
Orders as o
on c.Customer_ID=o.Customer_ID;
--Update the �Orders� table, set the amount to be 100 where �customer_id� is 3(Dont
have 3 so use 789 instead)
Update Orders set Amount=100 where Customer_ID=789;
-- Use the inbuilt functions and find the minimum, maximum and average amount from
the orders table
select min(Amount) from Orders;
--create a user-defined function, which will multiply the given number with 10
Create Function Mult_10(@num as int)
returns int
as
begin
return(
@num*10
)
end;
select dbo.mult_10(10);
--use the case statement to check if 100 is less than 200, greater than 200 or
equal to 200 and print the corresponding value
select case
When 100<200 then '100 Is less than 200'
When 100>200 then '100 is more than 200'
When 100=200 then '100 is equal to 200'
else NUll
End;