ich möchte eine Abfage nach der Differenz zwischen dem Wert (anzahl) aus COUNT(*) AS und einer Variable $var sortieren.
Das:
Code: Alles auswählen
$sql = "SELECT COUNT(*) AS anzahl, eintrag_id FROM tabelle WHERE t_id = *** AND t_id ... GROUP BY eintrag_id ORDER BY anzahl DESC";
Code: Alles auswählen
ORDER BY ABS(anzahl - " . $var . ") DESC"
Code: Alles auswählen
$sql = "SELECT COUNT(*) AS anzahl, eintrag_id FROM tabelle WHERE t_id = *** AND t_id ... GROUP BY eintrag_id ORDER BY ABS(anzahl - " . $var . ") DESC"
Wie kann ich mein Anliegen realisieren?