Autor Beitrag
flaavia
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: Fr 25.07.03 21:38 
Hallo

Die erste genannte SQL-Abfrage funktioniert, wenn ich diese um Count ergänze, funktioniert es nicht mehr:

folgendes funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('a, b, c where c = ' + Quotedstr(stringvariable) + 'order by b ASC');
ADOQuery1.Open

Wenn ich dies um Count ergänze (da ich die Anzahl der so erhaltenen Datensätze im weiteren brauche), kommt die unten genannte Fehlermeldung:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('a, b, c, count(c) where c = ' + Quotedstr(stringvariable) + 'order by b ASC');
ADOQuery1.Open

Fehlermeldung:
Zitat:
Sie wollen eine Abfrage ausführen, die den angegebenen Ausdruck 'a' nicht als Teil der Aggregatfunktion einschließt.

Kann mir jemand auf die Sprünge helfen, was mir das Orakel damit sagen will. Ich kann mit der Fehlermeldung nichts anfangen (welche Aggregatfunktion :?: ).

Vielen Dank für alle Tips im vorraus

Moderiert von user profile iconTino: Quote-Tags hinzugefügt; Code- durch Delphi-Tags ersetzt.
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 25.07.03 22:08 
Titel: hmm,
das ist ganz einfach, du kannst nicht zu jedem wert a alle werte c zusammenzählen. Darum mag er dies nicht.
Er müsste dann ja a mal alle c's zählen. Ich weiss nicht wie ich es besser erklären kann ich hoffe du weisst was ich meine !?

_________________
mfg. Joel
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: Sa 26.07.03 05:51 
Hallo JoelH

vielen Dank für die Antwort :D

was kann ich denn Abfragen um die Anzahl der ausgewählten Datensätze zu erhalten, die mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADOQuery1.Close; 
ADOQuery1.SQL.Clear; 
ADOQuery1.SQL.Add('a, b, c where c = ' + Quotedstr(stringvariable) + 'order by b ASC'); 
ADOQuery1.Open

erzeugt wurden (also wo die Bedingung c = Quotedstr(stringvariable) erüllt ist) :?:

ich habe mittlerweile folgendes ausprobiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADOQuery1.Close; 
ADOQuery1.SQL.Clear; 
ADOQuery1.SQL.Add('c, count(c) as Anzahl from tabelle where c = ' + Quotedstr(stringvariable)); 
ADOQuery1.Open

leider kommt wieder die Fehlermeldung:
Zitat:
Sie wollen eine Abfrage ausführen, die den angegebenen Ausdruck 'c' nicht als Teil der Aggregatfunktion einschließt.

bei:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADOQuery1.Close; 
ADOQuery1.SQL.Clear; 
ADOQuery1.SQL.Add('count(c) as Anzahl from tabelle where c = ' + Quotedstr(stringvariable)); 
ADOQuery1.Open

(also ohne c am Anfang des SQL-Textes) kommt die Fehlermeldung:
Zitat:
ADOQuery1: Field 'c' not found

blos wie geht es richtig :?: :nixweiss:

Moderiert von user profile iconTino: Quote-Tags hinzugefügt; Code- durch Delphi-Tags ersetzt.


Zuletzt bearbeitet von flaavia am Sa 26.07.03 08:25, insgesamt 1-mal bearbeitet
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: Sa 26.07.03 08:24 
hallo,

ich kenn mich mit den adokomponenten zwar nicht so gut aus, allerdings gibt es bei den InterbaseExpress kompos ein befehl, der sich Query.selectAll nennt. Also, entweder geht das nach dem ausführen des Querys ganz einfach mit Query.RecordCount, oder du musst das Select Statement ausführen, dann einmal Query.SelectAll machen und kannst dann Query.RecordCount auswerten.

Gruß
Ken

edit: Da war ich wohl schneller *G* :wink:

_________________
Eine Klasse beschreibt die Struktur und das Verhalten einer Menge gleichartiger Objekte.


Zuletzt bearbeitet von CenBells am Sa 26.07.03 09:56, insgesamt 1-mal bearbeitet
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Sa 26.07.03 08:32 
Titel: hmm,
flaavia hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADOQuery1.Close; 
ADOQuery1.SQL.Clear; 
ADOQuery1.SQL.Add('c, count(c) as Anzahl from tabelle where c = ' + Quotedstr(stringvariable)); 
ADOQuery1.Open

:

lass das count(c) weg und dann kannste einfach via der Methode recordcount , zumindestens bei einer TQuery Komponente, di eAnzahl der Datensätze erhalten die du zurück bekommst, naja und dass sind ja die die auch count(c) zurück liefern würde. Es ist nicht, schlecht möglich Aggregatsfunktionen, also meist Aufzählungen, mit normalen Feldern zu mischen da es eben ein Missmanagement ist. [/url]

_________________
mfg. Joel
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: Sa 26.07.03 08:36 
:idea: :beer:

Danke für die Tips

Werde ich gleich ausprobieren
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Sa 26.07.03 16:27 
Warum lässt Du net das c weg, dann müsste es funktionieren, die andere Variante über RecordCount verbrät Resourcen ohne Ende, weil er alle Daten rüberschaufeln muss.

Es ist eigentlich klar, warum die erste SQL-Anweisung net funktioniert, denn er müsste ja jedesmal alle c's zählen, wenn er einen ausgeben will, das lässt er halt net zu, ich kanns grad irgendwie nicht besser beschreiben :wink:
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Sa 26.07.03 17:18 
Titel: hmm,
UGrohne hat folgendes geschrieben:
Warum lässt Du net das c weg


weil er vielleicht alle c ' s braucht und noch den Gesamtcount dazu ?

_________________
mfg. Joel
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Sa 26.07.03 17:55 
Titel: Re: hmm,
JoelH hat folgendes geschrieben:
weil er vielleicht alle c ' s braucht und noch den Gesamtcount dazu ?

OK, das könnte ein Grund sein :P , hab irgendwie den Thread nur überflogen :wink:
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Sa 26.07.03 18:11 
Titel: hmm,
no Prob. solche Mods mag ich, konversation ist alles !!!

_________________
mfg. Joel
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Sa 26.07.03 18:46 
Titel: Re: hmm,
JoelH hat folgendes geschrieben:
no Prob. solche Mods mag ich, konversation ist alles !!!

Danke. Und zu Konversation ist ein Forum ja da, oder?
Na gut, jetzt aber Schluss hier, sind eh schon OffTopic, weiter mit dem Problem.... :wink:
Cashels
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 167



BeitragVerfasst: Sa 26.07.03 22:01 
flaavia hat folgendes geschrieben:
Sie wollen eine Abfrage ausführen, die den angegebenen Ausdruck 'c' nicht als Teil der Aggregatfunktion einschließt.

Yoh, genau das ist das Problem. Wenn du in deiner Select Abfrage Funktionen mit einbeschliesst, musst du dein Ergebnis gruppieren.

Im Klaren,
ausblenden Quelltext
1:
2:
select c, count(c) where c = 'Irgendwas'
group by c

sollte dann funktionnieren.

Lass mal den "where c=..." teil weg, und du verstehst sicherlich noch besser, wie mächtig diese Gruppierungsfunktionen sind.

Gruss,
Tom
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: Di 29.07.03 10:02 
:idea:

Vielen Dank für alle Tips :!:

@Cashels: kann ich dann auch noch die anderen Parameter a und b mit in die Abfrage einbeziehen, zusammen mit c und by c groupen?

ausblenden Quelltext
1:
2:
select a, b, c, count(c) where c = 'Irgendwas' 
group by c
Cashels
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 167



BeitragVerfasst: Di 29.07.03 13:07 
flaavia hat folgendes geschrieben:
kann ich dann auch noch die anderen Parameter a und b mit in die Abfrage einbeziehen, zusammen mit c und by c groupen?

ausblenden Quelltext
1:
2:
select a, b, c, count(c) where c = 'Irgendwas' 
group by a, b, c
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: Do 31.07.03 20:12 
:idea: :idea: :idea:

:D
Vielen Dank