electronicboy adlı üyeden alıntı: mesajı görüntüle
evet PK primary key
CATEGORYtablosu
PK_______NAMEIS
1________Yazılım
2________Mouse
3________Ekran Kartı
PRODUCTS tablosu
PK________NAMEIS________________CATEGORYPK
1_________Norton Antivirüs___________1
2_________Adobe Reader Pro________1
3_________Usb Mini Mouse___________2
4_________Radion Ekran Kartı_________3
CURRENTtablosu
PK________PRODUCTSPK_________AMOUNT_________PRICED OLLAR____MOTION
1_________4__________________20__________________1 50 _________1
2_________3__________________50__________________7 ____________1
3_________2__________________5___________________2 50__________1
4_________1__________________5___________________6 0___________1
5_________1__________________2___________________7 0___________0
6_________1__________________3___________________8 0___________0
7_________4__________________10__________________1 60__________0
tablo ve içindeki veriler bu şekilde.
Current tablosuna bakıldığında PRODUCTSPK 1 olan yani Norton Antivirüs şuan stokta bulunmamakta. MOTION 1 ile Norton Antivirüs 5 adet alınmış ve MOTION 0 ile 2+3 adet satılmış. benim istediğim ise mesela Yazılım alanında toplam kaç ürün alınmış (10), Toplam maliyeti (5*250+5*60 = 1550), Satılan ürün sayısı (2+3 = 5), Satılan üründen gelen para (2*70+3*80).
Şimdiden teşekkürler.

Yazılım alanında toplam kaç ürün alınmış
select sum(amount) as alinantoplam from current where productspk in (select pk from products where categorypk = 1) and motion = 1
Toplam maliyeti
select sum(amount*pricedollar) as toplammaliyet from current where productspk in (select pk from products where categorypk = 1) and motion = 1
Satılan ürün sayısı
select sum(amount) as toplammaliyet from current where productspk in (select pk from products where categorypk = 1) and motion = 0
Toplam gelen para
select sum(amount*pricedollar) as gelenpara from current where productspk in (select pk from products where categorypk = 1) and motion = 0
soruyu sorarken bi tablolari oluşturmak için sql dosyalarinizide ekleseydiniz. cevap vermek 10 dakika almazdı.

Belki sonra soruya erişenler olur diye sql dosyasi şu şekilde
# MySQL-Front Dump 2.5
#
# Host: localhost   Database: test
# --------------------------------------------------------
# Server version 4.1.22-community-nt


#
# Table structure for table 'category'
#

CREATE TABLE category (
  pk int(11) default NULL,
  nameis varchar(200) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;



#
# Dumping data for table 'category'
#

INSERT INTO category VALUES("1", "Yazilim");
INSERT INTO category VALUES("2", "Mouse");
INSERT INTO category VALUES("3", "Ekran Kart");


#
# Table structure for table 'current'
#

CREATE TABLE current (
  pk int(11) default NULL,
  productspk int(11) default NULL,
  amount int(11) default NULL,
  pricedollar int(11) default NULL,
  motion int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;



#
# Dumping data for table 'current'
#

INSERT INTO current VALUES("1", "4", "20", "150", "1");
INSERT INTO current VALUES("2", "3", "50", "7", "1");
INSERT INTO current VALUES("3", "2", "5", "250", "1");
INSERT INTO current VALUES("4", "1", "5", "60", "1");
INSERT INTO current VALUES("5", "1", "2", "70", "0");
INSERT INTO current VALUES("6", "1", "3", "80", "0");
INSERT INTO current VALUES("7", "4", "10", "160", "0");


#
# Table structure for table 'products'
#

CREATE TABLE products (
  pk int(11) default NULL,
  nameis varchar(200) default NULL,
  categorypk int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;



#
# Dumping data for table 'products'
#

INSERT INTO products VALUES("1", "Norton Antivirirus", "1");
INSERT INTO products VALUES("2", "Adobe Reader Pro", "1");
INSERT INTO products VALUES("3", "Usb Mini Mouse", "2");
INSERT INTO products VALUES("4", "Radion Ekran Karti", "3");