gpt4 book ai didi

sql - 以与我的 `IN(…)` 语句中的值相同的顺序返回带有 union all 的查询结果

转载 作者:搜寻专家 更新时间:2023-10-30 20:07:57 25 4
gpt4 key购买 nike

<分区>

我想按 IN 值对下面的查询进行排序,例如按电话 4444,6666,5555 的结果排序,...

(
select tab_a_user as user, tab_a_phone as phone
from table_a
where tab_a_phone in (4444, 6666, 5555, ...)
)
UNION ALL
(
select tab_b_user as user, tab_b_phone as phone
from table_b
where tab_b_phone in (4444, 6666, 5555, ...)
)

我试着像下面这样更改我的查询,但似乎缺少右括号

(
select tab_a_user as user, tab_a_phone as phone
from table_a
where tab_a_phone in (4444, 6666, 5555, ...)
order by field(phone,4444, 6666, 5555, ...))
UNION ALL
(
select tab_b_user as user, tab_b_phone as phone
from table_b
where tab_b_phone in (4444, 6666, 5555, ...)
order by field(phone,4444, 6666, 5555, ...))

IN 里面的值只是一个例子,因为在我的程序中,我会放一个变量,所以它会有一堆数据

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com