/* câu 1 */
Select * from Toys
/* câu 2 */
Select * from Shopper
/*Câu 3*/
Select * from recipient
/*Câu 4*/
Select vfirstname as firstname, vlastname as lastname, vEmailId as email from shopper
/*Câu 5*/
Select cOrderNo as so_hoa_don, cShippingModeId as cach_gui_qua,mGiftWrapCharges as
cach_goi_qua,mTotalCost as phi_goi_qua,mTotalCost as tong_so_tien from Orders
/*Câu 6*/
Select s.vToyName as ten, l.mToyCost as gia from Toys s, OrderDetail l where s.cToyId=l.cToyId
/*Câu 7*/
Select vToyName, siUpperAge- siLowerAge as agegroup from Toys
/*Câu 8*/
Select vToyName as Toy, siToyQoh as Quantity_on_hand, siToyWeight as Weight_from_Toys from Toys
/*Câu 9*/
Select vFirstName as Recipient_first_name, vLastName as Recipient_Last_name, vAddress as
Address ,cZipCode as Zip from Recipient
/*Câu 10*/
Select vFirstName,vLastName from Shopper where cState = N'California'
/*Câu 11*/
Select * from OrderDetail where mToyCost > 75
/*Câu 12*/
Select cToyId , mToyRate from Toys where vToyName =N'Baby Minnie' or vToyName = N'Dune Racer'
/*Câu 13*/
Select * from Toys where siToyQoh < 40
/*Câu 14*/
Select vToyName as Name, SUBSTRING ( vToyDescription,1,40) as Description , mToyrate as Rate from
Toys
/*Câu 15*/
Select cOrderNo as oder_Number, dShipmentDate as Shipment_date, dActualDeliveryDate as
Actual_Delivery_date, dActualDeliveryDate-dShipmentDate as days_in_transit from Shipment
/* câu 16*/
Select cOrderNo, cShopperId, dOrderDate , datename ( weekday, dOrderDate) as Weekday from Orders
/* câu 17*/
Select vToyName as Ten, cCategoryId as loai from Toys
/* câu 18 */
Select s.vToyName as Ten, b.cBrandName as nhan_hieu, s.cCategoryId as loai from Toys s , ToyBrand b
where s.cBrandId= b.cBrandId
/* cau 19*/
Select * into PremiumToys from Toys where mToyRate>20
/*câu 20*/
Select * from Shopper, Recipient
/*câu 21*/
Select s.vToyName as Toyname from Toys s ,Category y where s.cCategoryId=y.cCategoryId and
y.cCategory=N'Stuffed Toys'
/*câu 22*/
Select vToyName from Toys where mToyRate<20
/*câu 23*/
Select * from Toys s, ToyBrand d where s.cBrandId=d.cBrandId and d.cBrandName=N'Largo'
/*câu 24*/
Select * from Shopper where vCreditCardType=N'Master Card'
/*câu 25*/
Select * from Toys where cCategoryId=002
/* câu 26*/
Select * from Orders where dOrderDate= '2001-05-22 00:00:00.000'
/*câu 27*/
Select cOrderNo as Order_Number, mShippingCharges as Shipping_Charges, mGiftWrapCharges as
Gift_Wrap_Charges, mShippingCharges+mGiftWrapCharges as Handing_Charges from Orders
/*câu 28*/
Select * from Toys where mToyRate between 10 and 20
/*câu 29*/
Select vLastName as Ten, vEmailId from Shopper where cState =N'California' or cState=N'lllnois'
/*câu 30*/
Select cOrderNo as Order_Number, dOrderDate as Order_Date, cShopperId as Shopper_Id, mTotalCost
as Total_Cost from Orders where dOrderDate = '2001-05-20 00:00:00.000' and mTotalCost>75
/*câu 31*/
Select l.cOrderNo as Order_Number, l.cToyId as Toy_Id, r.vDescription as Wrapper_Description from
OrderDetail l, Wrapper r where l.cWrapperId = r.cWrapperId
/*cau 32*/
Select s.vToyName as Toy_name, t.cCartId as Cart_ID from ShoppingCart t , Toys s where t.cToyId =
s.cToyId
/* cau 33*/
Select concat ( left(vFirstName,1) ,'.', left (vLastName,1) ,'.')as Initials, vFirstName, vLastName from
Shopper
/* cau 34*/
Select round(mToyRate,1) as Gia from Toys
/* cau 35*/
Select r.cShopperId, s.cOrderNo from Shopper r, Orders s, Recipient t where r.cShopperId =
s.cShopperId and r.cState= t.cState
/* cau 36*/
Select * from Shopper into CaliforniaShoppers where cState='California'
/* loi sai trong cau*/
into phai dung truoc from
/* sua loi*/
Select * into CaliforniaShoppers from Shopper where cState='California'
/* câu 37*/
Select vFirstName as Ho, vLastName as Ten from Shopper where cCity= N'Woodbridge' or cCity= N'San
Jose' or cCity= N'Las Vegas'
/* câu 38*/
Select s.vToyName from Toys s , OrderDetail l where s.cToyId=l.cToyId and l.cGiftWrap=N'N'
/*câu 39*/
Select * from Orders s, Shipment t where s.cOrderNo=t.cOrderNo and t.cDeliveryStatus=N'd'
/*câu 40*/
a.
Select cOrderNo,cCity,cZipCode,cPhone,cState from Recipient
Union
Select cCity,cState,cZipCode,cPhone from Shopper
/* Loi sai */
Không cung so luong cot
b.
Select cCity,cZipCode,cPhone,cState from Recipient
Union
Select cCity,cPhone,cState,cZipCode from Shopper
/* loi sai */
Không cùng kieu du lieu va trat tu. bang tren la cua nguoi nhan, bang duoi la cua nguoi mua
/*câu 41*/
/*câu 42*/
/* câu 43*/
select * from Toys where cToyId not in ( select cToyId from OrderDetail)
/* câu 44*/
Select max(iTotalSold) from PickOfMonth
/*câu 45*/
a.
Select mTotalCost from Orders where YEAR (dOrderDate)= '2001'
b.
c.
Select month(dOrderDate) as thang, sum(mTotalCost) as doanh_thu from Orders group by
month(dOrderDate)
/*câu 46*/
/*câu 47*/
/*câu 48*/
/*câu 49*/
/*câu 50*/