我有 2 个表:今天的订单和记录
Table Name : Orders from today
+-----------+-----------+
|Order ID | Online |
+-----------+-----------+
| 550 | Yes |
| 551 | No |
| 552 | Yes |
| 553 | Yes |
+-----------+-----------+
Table Name : Records
+----------------+
| A |
+----------------+
| 548xxxxx |
| 549xxxxx |
| 550xxxxx |
| 551xxxxx |
| 552xxxxx |
| 553xxxxx |
| 554xxxxx |
+----------------+
XXXXX represents random number
我正在尝试根据“今日订单”表中订单 ID 的前 3 位数字,从“记录”表中获取完整记录。 我想要的结果是:
Table Name : Records
+----------------+
| A |
+----------------+
| 550xxxxx |
| 551xxxxx |
| 552xxxxx |
| 553xxxxx |
+----------------+
我尝试过使用:
SELECT * FROM 订单 WHERE orderid IN ( SELECT (LEFT(orderid, 3) FROM 样本));
但我只收到语法错误。我知道我可以使用 % 但我不知道如何适应代码。
请大家帮忙,非常感谢!
编辑! 假设今天起的订单中的订单ID不全是55%
谢谢!
最佳答案
可能的数据类型转换问题
尝试:
select *
from orders o1
left join records r2
on cast(o1.orderid as varchar(3)) = left(r2.orderid,3)
关于mysql - 在 where 子句中使用 Select left,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41227158/