0% found this document useful (0 votes)
17 views

Create Database Company1

database query for company instance

Uploaded by

bisrat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Create Database Company1

database query for company instance

Uploaded by

bisrat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Yared 56/70 group 14/15 self 5/5 yekrb aleka 7/10 total 82

create database company1

create table product(pid int,


pname varchar(40),descrption varchar(40), price int,
constraint pk primary key(pid)
)

create table orders(oid int primary key,


cname varchar(40),ordardate datetime,status char(30))

create table orderdetail


(pid int constraint pk foreign key references product(pid),
oid int foreign key references orders(oid),qty int)

insert into product values ( 6,'samsung','brand',2000)

insert into orders values (3,'aster','1/2/2000','complete')

insert into orderdetail values(1,1,6)

select * from orders


select * from orderdetail

select * from product

/*A*/ select cname from orders s left join orderdetail e on s.oid=e.oid


where e.oid is null

select cname from orders inner join orderdetail f on orders.oid=f.oid


group by
f.oid, orders.cname having
COUNT(orders.cname)>1

select cname from orders where ordardate = GETDATE()

select upper(cname) from orders


select distinct pname from product

select pname from product group by pname having COUNT(pname)>1

select cname+ ' ' + status from orders

select pname,price from product


where price in
(select price from product
group by price having
count(price)>1)

select COUNT(price) from product where price=2000

select pname from product c inner join orderdetail a on c.pid=a.pid where


a.pid = 2

select sum(price) as total from product


select pname from product where pname like ''
select * into productcopy2 from product where 1=2

select * from productcopy

select * from productcopy2

Select SUBSTRING(pname,2,3) as firstthree from product

select MAX(price) from product

You might also like