Professional Documents
Culture Documents
/*
unique : dups not allowed,null allowed
primary key : no dups and no nulls
not null : no null values
foreign key : to maintain referential integrity
default : to set a default value for some column
check : to check for a condition before inserting data
auto_increment : to increment a column value by 1 for each insertion
*/
-- CLAUSES:
-- ORDER BY : sort the data
-- default sort order is ascending
-- for descending sort, use DESC keyword in order by clause
/*
1001 rahul 40000 pune
1001 rahul 40000 pune
*/
-- top 15 rows
select * from emp_data limit 15;
-- 8th row
select * from emp_data limit 7,1;
-- dept_name=IT
select distinct salary from emp where dept_name='IT'
order by salary desc limit 4,1;
-- aggregate functions:
-- sum,min,max,avg,count
-- fetch count of emp and their avg salary from each loc
select loc,count(*),avg(salary) from emp_data group by loc;
-- count of movies which are released during holidays and their avg
revenue for each genre
-- select from order by limit group by
select genre,count(*),avg(`revenue(inr)`)
from movies
where `release period`='holiday'
group by genre
having count(*)>50;