-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueries and Types.txt
74 lines (49 loc) · 1.95 KB
/
Queries and Types.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
-- Finding Year,date,month from date format in MySQL --
select *, substr(birth_day,1,4) as birth_year from employee;
select first_name , extract(day from birth_day) from employee;
select first_name , extract(month from birth_day) from employee;
select first_name , extract(year from birth_day) from employee;
-- Current time finding --
select first_name ,current_timestamp() from employee;
select first_name ,current_date() from employee;
select first_name ,current_time() from employee;
-- Date , time finding with interval --
select first_name, current_date + interval '3' day from employee;
select first_name, current_time + interval '3' hour from employee;
select first_name, current_time + interval '3' minute from employee;
select first_name, current_time + interval '3' minute_second from employee;
-- Age Calculation --
select first_name, extract(year from current_date) - extract(year from birth_day) as age from employee;
-- Concat method --
SELECT * , concat(first_name,' ',last_name) as fname FROM companydatabase.employee;
--Null Values Handling --
-- Fill null values with NA--
SELECT Name , coalesce(Color,'NA') FROM adventureworks.product;
-- MySQL Constraints --
-- Database creation --
CREATE SCHEMA `mahindra` ;
use mahindra;
create table mahindra.employee_details(
id int not null unique ,
first_name varchar(20) not null,
last_name varchar(20) not null,
salary int not null,
dob date not null,
department varchar(50) not null default "Mahindra Holidays",
primary key(id)
);
-- Adding Constraints --
alter table employee_details
add constraint unique(first_name);
-- Single row data insertion --
insert into employee_details values(45,'Chandan','Sengupta',65000,'1988-01-11','data');
-- Case When Statement --
select first_name ,
case
when super_id=100 then 'Branch manager'
when super_id is null then ' Corporate manager'
else 'Associate'
end as 'designation'
from employee;
-- Distinct Count --
select count(distinct super_id) from employee;