MySQL Forums
Forum List  »  Turkish

2 tabloyu nasıl birleştiririm
Posted by: Ali Gel
Date: June 03, 2008 03:11AM

aşağıdaki gibi 2 tane tablom var.

1.TABLO: verilen_kontorler
id - musteri_id - urun_id - kontor
1 - 1 - 1 - 5
2 - 1 - 2 - 4
3 - 1 - 3 - 8
4 - 1 - 1 - 10
5 - 2 - 1 - 5
6 - 2 - 3 - 8
7 - 3 - 1 - 10


2.TABLO: harcamalar
id - musteri_id - urun_id - tarih
1 - 1 - 1 - 01.01.2000
2 - 1 - 3 - 01.01.2000
3 - 3 - 1 - 01.01.2000
4 - 2 - 1 - 01.01.2000
5 - 2 - 3 - 01.01.2000
6 - 1 - 2 - 02.01.2000
7 - 3 - 1 - 02.01.2000
8 - 1 - 2 - 02.01.2000
9 - 1 - 3 - 02.01.2000
10 - 1 - 1 - 02.01.2000
11 - 2 - 3 - 03.01.2000
12 - 3 - 1 - 03.01.2000
13 - 1 - 1 - 03.01.2000
14 - 1 - 3 - 03.01.2000

Bu tablolardan aşağıdaki sonucu tek bir sql komutuyla almak istiyorum

musteri_id - urun_id - verilen_kontor - harcanan_kontor
1 - 1 - 15 - 3
1 - 2 - 4 - 2
1 - 3 - 8 - 3

Not: mysql versiyonum sanirım 4.1 gibi bir şey. en son versiyon değil

---------------------------
yaptığım iki sorguda bu değerleri elde edebiliyorum
Fakat bir türlü iki tabloyu tek bir sorguda birleştiremedim

SORGU-1:
select verilen_kontorler.musteri_id, verilen_kontorler.urun_id, sum(verilen_kontorler.kontor) as verilen_kontor
from verilen_kontorler where (verilen_kontorler.musteri_id=1)
group by verilen_kontorler.urun_id

SONUÇ:
Musteri_id - Urun_id - verilen_kontor
1 - 1 - 15
1 - 2 - 4
1 - 3 - 8

SORGU-2:
select harcamalar.musteri_id, harcamalar.urun_id, count(harcamalar.id) as harcanan_kontor
from harcamalar where (harcamalar.musteri_id=1)
group by harcamalar.urun_id

SONUÇ:
Musteri_id - Urun_id - harcanan_kontor
1 - 1 - 3
1 - 2 - 2
1 - 3 - 3

Bu iki sorguyu nasıl birleştiririm ?



Edited 2 time(s). Last edit at 06/03/2008 03:14AM by Ali Gel.

Options: ReplyQuote


Subject
Views
Written By
Posted
2 tabloyu nasıl birleştiririm
10254
June 03, 2008 03:11AM
5909
June 05, 2008 12:11AM
4592
February 27, 2009 03:22AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.