Saturday, October 6, 2012

SQl Queries


create table movie_info(movie_name varchar(15), movie_id int , dvd_price float, no_of_dvd int )
select * from movie_info

insert into movie_info values('abc',101,400.67,45)
insert into movie_info values('xyz',102,300.62,24)
insert into movie_info values('qrs',103,250.78,72)
insert into movie_info values('abc',101,300.62,32)
insert into movie_info values('qrs',102,400.76,23)
insert into movie_info values('xyz',103,800.32,46)
insert into movie_info values('qrs',102,250.78,90)
insert into movie_info values('twv',101,567.46,82)

select round(dvd_price,1) "DVD Price", no_of_dvd  from movie_info where dvd_price > 250.0 and no_of_dvd >1 order by dvd_price

select movie_name, sum(no_of_dvd) , max(no_of_dvd)"Max No. of DVDS"  from movie_info where movie_name like '%c' or movie_name like '%s' group by movie_name having max(no_of_dvd) > 45

select 'Movie Code : '+substring(movie_name,1,1)+ substring(movie_name,3,1)+ ' have total no of dvds as '+ cast(avg(no_of_dvd)as varchar(30))+ ' and Average no of DVDs ' + cast(sum(no_of_dvd) as varchar(30)) "Movie Info" from movie_info group by movie_name


No comments:

Post a Comment