On Mon, 2005-02-21 at 10:16 +0700, riko ms wrote:
> pake db apa nih?
> kl mysql, sy pake:
> 
> select kode, name,
> sum(if(month(tgl) = '1'), nilai, 0) as jan,
> sum(if(month(tgl) = '2'), nilai, 0) as peb,
> jan+peb as total
> from name_tabel
> group by month(tgl)
> 
> sori, query ini belum di validasi di mysql :)
> tp kira2 bgt.
> 
> -rik-

ada sedikit ralat:

select
  kode, name,
  sum(if(month(tgl) = '1', nilai, 0)) as jan,
  sum(if(month(tgl) = '2', nilai, 0)) as peb,
  sum(if(month(tgl) = '1', nilai, 0) +
    if(month(tgl) = '2', nilai, 0)) as total
from
  name_tabel
group by
  kode, name

di Oracle:

select
  kode, name,
  sum(decode(month(tgl), 1, nilai, 0)) as jan,
  sum(decode(month(tgl), 2, nilai, 0)) as peb,
  sum(decode(month(tgl), 1, nilai, 0) +
    decode(month(tgl), 2, nilai, 0)) as total
from
  name_tabel
group by
  kode, name


-- 
Danny Kurniawan
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/CM/E/IT d+() s+:+ a- C++>+++$ UL+++(++)>++++ P!(+++) L+++>++++>$ E-- W++>$ N
o-- K- w--(+++) O++@ M@ V? PS PE-@ Y+ PGP@ t++ 5+@ X+++(++) R tv+ b
+++(++) DI? D++@ G+>++ e++ h- r++ y z- 
------END GEEK CODE BLOCK------


-- 
Berhenti langganan: [EMAIL PROTECTED]
Arsip dan info: http://linux.or.id/milis

Kirim email ke