문제

I have the following query:

SELECT url, url_hash from pages WHERE url_hash IN (SHA1('URL1'), SHA1('URL2'), SHA1('URL3'))
ORDER BY FIND_IN_SET(url_hash, "SHA1('URL1'), SHA1('URL2'), SHA1('URL3')")

I would to keep the order of the result set the same as the order of the parameters in the IN clause.

I've found this SO question.

The problem is that mysql doesn't know how to interpret a set of SHA1 functions, if I pass them as strings, they are not evaluated correctly, and if I pass them an an expression (without quotes) I get the following error:

OperationalError: (1582, "Incorrect parameter count in the call to native function 'FIND_IN_SET'")
도움이 되었습니까?

해결책

I think you want to use field() rather than find_in_set():

SELECT url, url_hash
from pages 
WHERE url_hash IN (SHA1('URL1'), SHA1('URL2'), SHA1('URL3'))
ORDER BY field(url_hash, SHA1('URL1'), SHA1('URL2'), SHA1('URL3'));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top