错误在哪里?
SELECT * FROM papiry
WHERE (aktivni=1 AND pocetovereni>1 ORDER BY pocetovereni DESC LIMIT1)
AND oddeleni='$oddeleni' ORDER BY nazev ASC;
感谢您的帮助,我不擅长 SQL。
错误在哪里?
SELECT * FROM papiry
WHERE (aktivni=1 AND pocetovereni>1 ORDER BY pocetovereni DESC LIMIT1)
AND oddeleni='$oddeleni' ORDER BY nazev ASC;
感谢您的帮助,我不擅长 SQL。
你有一个糟糕的 SQL,ORDER BY
不是要在子句中输入的WHERE
子句。一个潜在的优秀 SQl 看起来像这样:
SELECT * FROM papiry
WHERE aktivni=1
AND pocetovereni>1
AND oddeleni='$oddeleni'
ORDER BY ORDER BY pocet, overeni DESC, nazev ASC;
但是,您必须决定要按哪些列排序。这是在 SQL 命令的末尾定义的。
SELECT *
FROM papiry
WHERE (aktivni = 1 AND pocetovereni > 1)
AND oddeleni='$oddeleni'
ORDER BY
CASE WHEN ktivni = 1 AND pocetovereni > 1 THEN pocetovereni END DESC,
CASE WHEN oddeleni='$oddeleni' THEN nazev END ASC
Order By 必须出现在 WHERE 子句之后,这至少在 SQL Server 中有效:
SELECT * FROM papiry
WHERE aktivni=1 AND pocetovereni>1 AND oddeleni='$oddeleni'
ORDER BY pocetovereni DESC, nazev ASC