"select top 5 db_statesid
from seo_states
where db_statesid in (" +
"SELECT TOP 5 db_statesid
FROM (SELECT DISTINCT a.db_statesid
FROM seo_states a
where country_id=" + country_id + ")
ORDER BY RND(db_statesid))";
我正在使用此查询进行访问,但它工作正常但不适用于在Order by附近发出语法错误的SQL。
答案 0 :(得分:2)
在sql中,所有派生表都必须是别名。请注意在t1
ORDER BY
"select top 5 db_statesid
from seo_states
where db_statesid in (" +
"SELECT TOP 5 db_statesid
FROM (SELECT DISTINCT a.db_statesid
FROM seo_states a
where country_id=" + country_id + ") t1
ORDER BY RND(db_statesid))"
修改
除非RND
是自定义函数,否则您可能需要RAND