MATERI-MATERI MATA KULIAH SISTEM INFORMASI STMIK MDP

Pasang Iklan Gratis Disini !!!

ads ads ads ads

Kamis, 15 Maret 2012

Total Harga, Total Barang, Sum, Min, Max, Avg

. Kamis, 15 Maret 2012

create database pertemuan4
use pertemuan4

create schema ScPalembang

create table ScPalembang.TblBarang
(
Kode Varchar (20) primary key,
Nama Varchar (200) not null,
Harga bigint not null,
Jumlah int not null
)

Select * from ScPalembang.TblBarang

insert into ScPalembang.TblBarang
(Kode, Nama, Harga, Jumlah)
values ('KK3', 'Kepala Kambing' ,4000000, 55)

insert into ScPalembang.TblBarang
(Kode, Nama, Harga, Jumlah)
values ('TI4', 'Tulang Iga' ,90000000, 70)

'TOTAL HARGA
Select *, Harga * Jumlah as "Total Bayar" from ScPalembang.TblBarang

'TOTAL BARANG
select SUM (Jumlah) as "Total Barang" from ScPalembang.TblBarang

'HARGA TERENDAH
select MIN (Jumlah) as "Harga Terendah" from ScPalembang.TblBarang

'HARGA TERTINGGI
select MAX (Jumlah) as "Harga Tertinggi" from ScPalembang.TblBarang

'RATA-RATA
select AVG (Jumlah) as "Rata-rata Harga" from ScPalembang.TblBarang

'Select 2 Teratas
Select top 2 * from  ScPalembang.TblBarang

'Select Separoh Tabel
Select top 50 percent * from ScPalembang.TblBarang

'Urutan dr yg Kecil
Select * from ScPalembang.TblBarang order by Jumlah asc

'Urutan dr yg Besar
Select * from ScPalembang.TblBarang order by Nama desc

'FILTER
Select * from ScPalembang.TblBarang where Harga > 16000000
Select * from ScPalembang.TblBarang where Jumlah >20 and Harga > 16000000
Select * from ScPalembang.TblBarang where Jumlah >20 or Harga > 16000000
Select * from ScPalembang.TblBarang where Jumlah between 50 and 70
'and = kedua kondisi harus TRUE
    EX : HARGA : JUMLAH : HASIL
               T                 T              T
               T                 F              F
'or  = Salah satu ada yang TRUE

'MENCARI DATA
Select * from ScPalembang.TblBarang where Nama like 'K%'    --> Huruf Depan
Select * from ScPalembang.TblBarang where Nama like '%G'    --> Huruf Belakang
Select * from ScPalembang.TblBarang where Nama like '%Y%'    --> Huruf Dimanapun Tempatny

'STRING CONCATENATION
select 'Bpk. ' + Nama from ScPalembang.TblBarang

'STRING EXTRACTORS
Select left (nama,2) as 'LEFT' from ScPalembang.TblBarang
Select right (nama,2) as 'RIGHT' from ScPalembang.TblBarang
Select *, Substring (nama,2,2) as 'SUBSTRING, 2, 2' from ScPalembang.TblBarang

'UPPER AND LOWER FUNCTION
Select UPPER (nama) As nama from ScPalembang.TblBarang
Select LOWER (nama) As nama from ScPalembang.TblBarang

'LEN FUNCTION
Select nama, LEN (nma) As 'Jumlah Karakter' from ScPalembang.TblBarang
Select *, LEN (nama) As 'Jumlah Karakter' from ScPalembang. Tbl Barang

SEMOGA BERMANFAAT

0 komentar:

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Posting Komentar

Tuliskan Komentar Disini..

Related Posts Plugin for WordPress, Blogger...
 
{Sistem Informasi} is proudly powered by Blogger.com | Template by : Sukriyadi | sukriyadi.blogspot.com