|
| 1 | +-- Step 1 Create DataBase |
| 2 | +create database cwpc111; |
| 3 | +-- Step 2 select database |
| 4 | +use cwpc111; |
| 5 | +-- Step 3 create a new table |
| 6 | +create table customers( |
| 7 | + customerID int primary key, |
| 8 | + name varchar(100), |
| 9 | + mobile varchar(100), |
| 10 | + age int, |
| 11 | + creditlimit bigint, |
| 12 | + dob date, |
| 13 | + bank enum("HDFC","SBI","ICICI") |
| 14 | +); |
| 15 | +-- show tables records |
| 16 | +select * from customers; |
| 17 | +-- insert record into table |
| 18 | +insert into customers |
| 19 | +(customerid,name,mobile,age,creditlimit,dob,bank) |
| 20 | +values(1,"nishant","7894562100",14,45000,"2015-04-23","ICICI"), |
| 21 | +(2,"Riya","7894562100",14,45000,"2015-04-23","ICICI"), |
| 22 | +(3,"Neha","7894562100",14,45000,"2015-04-23","HDFC"), |
| 23 | +(4,"Rohan","7894562100",14,45000,"2015-04-23","ICICI"); |
| 24 | + |
| 25 | +insert into customers(customerid,name,mobile,age,dob,bank) |
| 26 | +values(10,"nishant","7894562100",14,"2015-04-23","ICICI"); |
| 27 | + |
| 28 | +-- empty table |
| 29 | +truncate table customers; |
| 30 | +select * from customers; |
| 31 | +-- delete table |
| 32 | +drop table customers; |
| 33 | +-- check table |
| 34 | +show tables; |
| 35 | + |
| 36 | +-- find the list of databases |
| 37 | +show databases; |
| 38 | +-- create a new database |
| 39 | +create database cwpc90; |
| 40 | +-- delete database |
| 41 | +drop database cwpc90; |
| 42 | +-- select database |
| 43 | + |
| 44 | +-- create a table |
| 45 | +create table Employee( |
| 46 | + emp_id int, |
| 47 | + name varchar(100), |
| 48 | + city varchar(100), |
| 49 | + dob date, |
| 50 | + salary int, |
| 51 | + age int, |
| 52 | + dept enum("hr","sales","it") |
| 53 | +); |
| 54 | + |
| 55 | +-- show list of tables |
| 56 | +show tables; |
| 57 | + |
| 58 | +-- show table record |
| 59 | +select * from employee; |
| 60 | + |
| 61 | +-- insert record into table |
| 62 | + |
| 63 | +insert into employee (emp_id,name,city,dob,salary,age,dept) |
| 64 | +value(101,"nishant","mumbai","1990-11-23",45000,32,"sales"); |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +-- date 5 oct 2026 |
| 69 | + |
| 70 | + |
| 71 | +use classicmodels; |
| 72 | + |
| 73 | +show tables; |
| 74 | + |
| 75 | +-- check customers table records |
| 76 | +select * from customers; |
| 77 | +select customernumber,customername,country,city,creditlimit |
| 78 | +from customers; |
| 79 | +-- update |
| 80 | +select * from customers where customernumber = 125; |
| 81 | + |
| 82 | +update customers set creditlimit = 10000 |
| 83 | +where customernumber = 125; |
| 84 | +-- delete |
| 85 | +delete from customers where customernumber = 125; |
| 86 | +-- where |
| 87 | +-- and |
| 88 | +select * from customers where country = "USA" and creditlimit > 50000; |
| 89 | +-- or |
| 90 | +select * from customers where creditlimit > 100000 and creditlimit < 200000; |
| 91 | +-- count() |
| 92 | +select count(*) from customers |
| 93 | +where creditlimit > 100000 and creditlimit < 200000; |
| 94 | + |
| 95 | +select customername , country , creditlimit from customers |
| 96 | +where country = "USA" and creditlimit < 100000; |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +-- 8 Oct 2026 |
| 102 | +create database CWPC_Company; |
| 103 | +use CWPC_Company; |
| 104 | + |
| 105 | +create table employees( |
| 106 | + employee_id int primary key, |
| 107 | + name varchar(50), |
| 108 | + department varchar(50), |
| 109 | + salary decimal(10,2), |
| 110 | + city varchar(50), |
| 111 | + joining_date Date, |
| 112 | + manager_id int |
| 113 | +); |
| 114 | + |
| 115 | +select * from employees; |
| 116 | + |
| 117 | + |
| 118 | +-- limit |
| 119 | +select * from employees limit 3; |
| 120 | + |
| 121 | +-- order by |
| 122 | +select * from employees order by salary desc limit 5; |
| 123 | +select * from employees order by salary asc limit 5; |
| 124 | + |
| 125 | +-- offset 2 (First 2 row skip) |
| 126 | +select * from employees limit 6 offset 9; |
| 127 | +select * from employees where employee_id > 9 and employee_id < 16; |
| 128 | + |
| 129 | +-- is NULL |
| 130 | +select * from employees where manager_id is NULL; |
| 131 | + |
| 132 | +-- is not NULL |
| 133 | +select * from employees where manager_id is not NULL; |
| 134 | + |
| 135 | +-- total record not null |
| 136 | + |
| 137 | +select count(*) from employees where manager_id is not NULL; |
| 138 | + |
| 139 | +-- coalesce() |
| 140 | +select name , coalesce(manager_id,0) as manager_id from employees; |
| 141 | + |
| 142 | +select count(*) from employees where Department = "IT"; |
| 143 | + |
| 144 | +-- distinct |
| 145 | +select distinct Department from employees; |
| 146 | +-- count() - Department |
| 147 | +select count(distinct Department) from employees; |
| 148 | + |
| 149 | +-- group by |
| 150 | +select Department , count(Department) as total_employee |
| 151 | +from employees group by Department; |
| 152 | + |
| 153 | +select name , salary , salary * 1.10 as new_salary |
| 154 | +from employees where Department = "IT"; |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | + |
0 commit comments