MySQL Forums
Forum List  »  German

Re: Subquery returns more than 1 row
Posted by: Mark Knochen
Date: January 11, 2012 03:55AM

Ich habe das Beispiel mal erweitert - und da kommen wir dann zum Problem:




CREATE TABLE IF NOT EXISTS `items` (
`ItemName` varchar(10) NOT NULL,
`itemId` int(11) NOT NULL,
`id_gender` int(11) NOT NULL,
`brand` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `items` (`ItemName`, `itemId`, `id_gender`, `brand`) VALUES
('Suit1', 1, 1, 'Suit'),
('Suit2', 2, 2, 'Suit'),
('Suit3', 3, 1, 'Suit'),
('Test1', 4, 1, 'Test'),
('Test2', 5, 2, 'Test'),
('Test3', 6, 1, 'Test');




CREATE TABLE IF NOT EXISTS `items_stock` (
`itemStockId` int(11) NOT NULL,
`itemId` int(11) NOT NULL,
`PhysicalStock` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


INSERT INTO `items_stock` (`itemStockId`, `itemId`, `PhysicalStock`) VALUES
(1, 1, 10),
(2, 1, 5),
(3, 2, 20),
(4, 2, 5),
(5, 3, 30),
(6, 3, 5),
(7, 6, 7),
(8, 6, 8),
(9, 4, 9),
(10, 4, 10),
(11, 5, 11),
(12, 5, 12);


Wenn ich jetzt hier nach den Summen abfragen will und
zusätzlich noch nach einem attribut, wie id_gender, dann
bringen die folgenden Abfragen

--------------------------------------------

SELECT items.brand, (

SELECT SUM( its.PhysicalStock )
FROM items_stock AS its
WHERE its.itemId = items.itemId
) AS stockValue
FROM items

GROUP BY items.brand

--------------------------------------------

SELECT items.brand, (

SELECT SUM( its.PhysicalStock )
FROM items_stock AS its
WHERE its.itemId = items.itemId
) AS stockValue
FROM items
WHERE items.id_gender = '1'
GROUP BY items.brand

--------------------------------------------

das gleiche ergebnis, was aber nicht sein kann.

Ich glaube, so ist das Problem deutlicher - und ich komme hier nicht weiter.

Danke schonmal

Mark

Options: ReplyQuote


Subject
Views
Written By
Posted
3110
December 15, 2011 08:48AM
1787
December 15, 2011 12:41PM
1608
January 06, 2012 09:51AM
Re: Subquery returns more than 1 row
1261
January 11, 2012 03:55AM
1294
January 11, 2012 08:26AM
1498
January 12, 2012 04:52AM
2047
January 12, 2012 06:33AM
1529
January 13, 2012 03:27AM


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.