这是我的查询,查询将向用户显示哪个id首先为2,并且联合除用户ID 2之外的其他用户。
(SELECT account.accountid,account.accountname FROM account,entity WHERE entity.id = account.accountid AND entity.deleted=0 AND account.accountid = 2)
UNION
(SELECT account.accountid,account.accountname FROM account,entity WHERE entity.crmid = account.accountid AND entity.deleted=0 AND account.accountid NOT IN(2) ORDER BY account.accountname )
查询显示结果非常好但订单依据不起作用。 我在这里要做什么?
请帮帮我。
答案 0 :(得分:1)
使用首先按account.accountid = 2
排序然后按account.accountname
SELECT account.accountid,account.accountname
FROM account,entity
WHERE entity.id = account.accountid
AND entity.deleted=0
order by case when account.accountid = 2 then 1 else 2 end,
account.accountname