Re: OK wenn nicht vorhanden
CREATE TABLE test_summe (
id INT NOT NULL,
menge INT NOT NULL
);
INSERT INTO test_summe VALUES
( 1, 0 ),
(10 , 10);
/* 1) vorhanden, menge = 0*/
SELECT id, SUM(menge) AS menge
FROM test_summe
GROUP BY id
HAVING SUM(menge) = 0;
+----------+-------+
| id | menge |
+----------+-------+
| 1 | 0 |
+----------+-------+
1 row in set (0.08 sec)
/* 2) vorhanden, menge > 0 */
SELECT id, SUM(menge) AS menge
FROM test_summe
GROUP BY id
HAVING SUM(menge) > 0
+----+-------+
| id | menge |
+----+-------+
| 10 | 10 |
+----+-------+
1 row in set (0.00 sec)
/* 3) nicht vorhanden */
SELECT COUNT(*), SUM(menge) AS menge
FROM test_summe
WHERE id = 100;
+----------+-------+
| COUNT(*) | menge |
+----------+-------+
| 0 | NULL |
+----------+-------+
1 row in set (0.00 sec)
Ein paar kleine Beispiele dazu. Ansonsten hoffen wir, dass Dir morgen früh die ultimative Lösung einfällt.
Grüße
Thomas
Edited 1 time(s). Last edit at 10/31/2010 01:04PM by Thomas Wiedmann.
Subject
Views
Written By
Posted
3630
October 29, 2010 03:09PM
1272
October 31, 2010 09:26AM
1391
October 31, 2010 11:28AM
Re: OK wenn nicht vorhanden
1333
October 31, 2010 01:03PM
1195
October 31, 2010 02:58PM
1566
October 31, 2010 03:57PM
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.