错误在哪里?
SELECT * FROM papiry
WHERE (aktivni=1 AND pocetovereni>1 ORDER BY pocetovereni DESC LIMIT1)
AND oddeleni='$oddeleni' ORDER BY nazev ASC;
感谢您的帮助,我不擅长SQL。
答案 0 :(得分:1)
您的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命令结束时定义的。
答案 1 :(得分:1)
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
答案 2 :(得分:0)
Order By必须出现在WHERE子句之后,这至少可以在SQL Server中使用:
SELECT * FROM papiry
WHERE aktivni=1 AND pocetovereni>1 AND oddeleni='$oddeleni'
ORDER BY pocetovereni DESC, nazev ASC