Ich möchte die Nummer der ABC-Gruppe mit ID zählen.Select-Anweisung mit Count
SELECT group, count(id) as total FROM `user` WHERE group=`ABC`;
Was ist los? Vielen Dank.
Ich möchte die Nummer der ABC-Gruppe mit ID zählen.Select-Anweisung mit Count
SELECT group, count(id) as total FROM `user` WHERE group=`ABC`;
Was ist los? Vielen Dank.
Fügen Sie die Spalten in der Auswahlliste in die group by
-Klausel ein, wenn Aggregatfunktionen verwendet werden.
SELECT group, count(id) as total FROM user
WHERE group=`ABC`
GROUP BY group
Sonst einfach die Anzahl ohne Verwendung anderer Spalten in der Select-Anweisung abrufen.
SELECT count(id) as total FROM user
WHERE group=`ABC`
Try this:
SELECT group, count(id) as total FROM `user`
group by group having group like 'ABC';
Wenn Sie COUNT von Benutzern erhalten möchten, die die "Gruppe" -Feld hat = "ABC"
SELECT count(id) as total FROM user WHERE group='ABC';
Außerdem ist es besser zu vermeiden Verwenden von SQL-Schlüsselwörtern in Spaltennamen (GROUP ist ein SQL-Schlüsselwort)
Ich werde Sie das gleiche fragen, was ist falsch? –
Was [tag: rdbms] verwenden Sie? Und welchen Fehler bekommst du? – Mureinik
Das ist ungültiges SQL - Sie müssen die Spalte '" group "' in eine 'group by' Anweisung aufnehmen. –