Autor Beitrag
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 30.07.03 10:22 
Hi Leutz,

Ich habe eine Datenbank (DBase) mit den Feldern (nur Bsp.!):
- Name
- Schulden

Jetzt möchte ich mir eine Liste anzeigen lassen, nach dem Schema:
Name | Gesamtschulden

Ich möchte also (muss vielleicht nicht über SQl sein) von einer Person (Feld Name) alle Schulden (da die personen mehrmals vorkommen können) zusammenrechnen lassen und ein neues Feld (Gesamtschulden) anzeigen lassen.

Wie geht das?
Danke im Vorraus.

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)


Zuletzt bearbeitet von GSE am Mi 30.07.03 13:34, insgesamt 2-mal bearbeitet
inselberg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458



BeitragVerfasst: Mi 30.07.03 10:38 
SELECT SUM(schulden) FROM tabelle WHERE name = 'armer schlucker'

;)

_________________
hans bist du das ?
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 30.07.03 10:54 
Danke, aber so bekomme ich nur für einen Mitarbeiter das raus.

ich wollte ja eine Liste wie:

Name | Gesamt (€)
-------|--------------
Josef | 100
Ulli | 23
jesu | 65

bei deiner Lösung krieg ich´s ja nur für einen Mitarbeiter raus.

gibt´s ne Lösung wo ich so´ne Liste krieg?

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
inselberg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458



BeitragVerfasst: Mi 30.07.03 11:05 
kann deine datenbank subqueries ?

sonst musst du halt in einer liste alle namen auswählen (select distinct)

und dann name für name in der select sum abarbeiten...

_________________
hans bist du das ?
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 30.07.03 11:19 
Was sind subqueries?

Sorry bin keine große Leuchte auf dem DB-Gebiet.

(heißt ja soviel wie "Unter"-Query, aber wie wende ich das an?)

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Mi 30.07.03 11:27 
Auf keinen Fall Subqueries benutzen!

Das würde die Abfrage ewig langsam machen!

Die einfachste Variante geht so:

SELECT name, SUM(Schulden) AS Schuldenberg FROM Tabelle GROUP BY Name

Alles andere belastet die Datenbank nur unnötig!

Viele Grüße,

Matthias

P.S.: dBase unterstützt ohnehin keine Subqueries.

_________________
Ha! Es compiliert! Wir können ausliefern!
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 30.07.03 11:46 
@neojones: Danke, funktioniert einwandfrei

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 30.07.03 12:21 
Hab´s jetzt so gemacht:
ausblenden Delphi-Quelltext
1:
2:
3:
SELECT Name, SUM(Schulden) FROM Buchung.dbf
WHERE ( NR like '12' )
GROUP BY Name


Wie ihr seht muss ich es noch mit Nummern filtern.

(Bsp-Tabelle:
Name|Schulden|Nr
Uwe|1|23
Ulli|554|12
Olaf|12|23
Uwe|32|23
Jetzt möchte ich die Namen anzeigen lassen, mit den gesamtschulden (was ich ja schon habe), aber nur wenn die projektnr. beim Nummer z. Bsp. 12 ist)

Wenn ich jetzt die Schulden zählen lasse, und die Nummern (23) filter sollte das rauskommen:
Uwe|33
Olaf|12

hoffe ihr habt´s verstanden!

Wer kann mir also helfen?

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Mi 30.07.03 12:24 
Ähm, versteh leider nicht gant, was Du meinst. Aber wie wärs damit:

ausblenden Quelltext
1:
2:
WHERE Nummer=12
Group By Name, Nummer


Wenn das nicht das gewünscht Ergebnis ist, beschreib nochmal was Du machen willst.

Viele Grüße,

Matthias

_________________
Ha! Es compiliert! Wir können ausliefern!
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 30.07.03 12:28 
Zitat:
Wenn das nicht das gewünscht Ergebnis ist, beschreib nochmal was Du machen willst.

mach ich, und zwar möchte ich das, was du mir oben schon gegeben hast mit drinn behalten, aber wenn eben die Nummer nicht übereinstimmt sollen diese Schulden nicht mitgerechnet werden.

Wie gesagt hab´nicht so viel (eigentlich keine) Ahnung von SQL.

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Mi 30.07.03 12:36 
Dann müsste das so aber gehen, wie ich oben schon schrieb.

Ich würde allerdings auf keinen Fall LIKE benutzen, wenn es eine Zahl ist. LIKE ist langsamer als "=".

Schreib mal, was für eine Ergebnismenge er mit der Abfrage von oben bringt, wenn sie nicht stimmt.

Viele Grüße,

M

_________________
Ha! Es compiliert! Wir können ausliefern!
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 30.07.03 12:51 
Danke, funktioniert doch.

mfg
GSE

P.S.:Ich muss aber "like" verwenden da die Nummern z.Bsp.: so aussehen K0001

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Mi 30.07.03 13:10 
Naja, auch da würde ich eher mit einem "=" arbeiten und dann halt den Wert dahinter in Hochkommata setzen. LIKE ist eigentlich nur notwendig, wenn man Wildcards ('%' oder '_') benutzt, um unscharfe Werte abzufragen.

Viele Grüße,

Matthias

_________________
Ha! Es compiliert! Wir können ausliefern!