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

SQLQuery3 (Hari Ke-2)

Uploaded by

Adrian Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQLQuery3 (Hari Ke-2)

Uploaded by

Adrian Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

select [Product], [Segment], [Sale_Price] from production.

financial where
[Units_Sold]>1000;

select Product, Sale_Price


From [production].[financial]
where Product like '%o%' or (Country='Canada' and units_sold>1500);

select distinct country from production.financial where country<>'United States of


America'

select distinct country from production.financial where country in ('United States


of America', 'Canada');

select * from production.financial where month_number between 1 and 4

--menampilkan segment yang tidak diawali huruf A-G


select distinct segment from production.financial where segment like '[^A-G]%'

-- menampilkan segment yang diawali huruf A-G


select distinct segment from production.financial where segment like '[A-G]%'

select country from production.financial group by country

select MIN(units_sold) as Penjualan from production.financial

select product, sale_price


from production.financial
where units_sold=(select Max(units_sold) as Penjualan from
production.financial)

select product, sale_price


from production.financial
where units_sold=(select Min(units_sold) as Penjualan from
production.financial)

select sum(profit) from production.financial

select country,sum(profit) as Untung


from production.financial
group by country

select sum(profit) from production.financial where country='canada'

select count(distinct segment) from production.financial

select distinct segment from production.financial

select Product,sum(sales) as Penjualan,sum(Profit) as Untung


from Production.financial
where (month_number between 9 and 11) and years=2014
group by product
having sum(profit) > 350000

select month_number,month_name,sum(sales) as Penjualan


from Production.financial
where years=2014
group by month_number, month_name
order by month_number asc
Select country,product,units_sold,sales
into production.keuangan
from production.financial
alter table production.keuangan
add kode_negara char(20) null

select substring(country,1,2) from production.keuangan

update production.keuangan
set kode_negara=(select substring(country,1,2)
from production.keuangan
where kode_negara is null

Select country from production.financial


union
select country from production.keuangan

update production.keuangan set country='Canada' where sales < 200000

Select country from production.financial


Intersect
select country from production.keuangan

Select country from production.financial


union
select country from production.keuangan

Select country from production.financial


except
select country from production.keuangan

Select country,kode_negara=
case country
when 'canada' then 'Ca'
when 'malaysia' then 'Ma'
when 'Indonesia' then 'Idn'
else 'Kosong'
END
from production.keuangan

Select product,sum(profit) as keuntungan,keterangan=


case
when sum(profit) between 0 and 2000000 then 'biasa'
when sum(profit) > 2000000 and sum(profit) <= 2500000 then 'mantap'
when sum(profit) > 2500000 then 'luarbiasa'
else 'Tidak Valid'
END
from production.financial
group by product

Select country,product,units_sold,sales,profit
into production.keuangan
from production.financial
alter table production.keuangan
add kode_negara char(20) null

Update production.keuangan set kode_negara=


case country
when 'Canada' then 'Ca'
when 'Malaysia' then 'My'
when 'Indonesia' then 'Id'
else 'Kosong'
END
from production.keuangan

Insert into production.keuangan(Discounts)


select Discounts from production.financial
group by Discounts

alter table production.keuangan


add Discounts char(20) null

Select country,
case country
when 'canada' then 'Ca'
when 'malaysia' then 'Ma'
when 'Indonesia' then 'Idn'
else 'Kosong'
END kode_negara
from production.keuangan

Select country, product from production.keuangan


where country in (Select country from production.keuangan where
sales>1000000 group by country)
group by country,product

create table production.negara (


kode_negara char (5) primary key,
nama_negara varchar (80) not null
);

insert into production.negara values ('CA','Canada')


insert into production.negara values ('ME','Mexico')
insert into production.negara values ('IDN','Indonesia')

select country, product from production.keuangan


where country in (select nama_negara from production.negara)
group by Country,Product

You might also like