我在这里有此代码,该代码从想要的列中选择13个字符:

`select barcode, substring(barcode,1,13) as test from outerbarcodes


我需要选择前13个字符并将其与另一个表连接。但是我不想创建一个新表然后加入。在Workbench中仅显示结果的方式是什么?

我尝试了以下方法:

`select barcode, substring(barcode,1,13) as test from outerbarcodes join bridgeb on
`outerbarcodes.test = bridgeb.barcode

最佳答案

select barcode, substring(barcode,1,13) as test from outerbarcodes join bridgeb on
outerbarcodes.test = bridgeb.barcode


ONWHERE子句中不能使用选择别名,选择别名只能在HAVING子句中使用

你需要做

select barcode, substring(barcode,1,13) as test from outerbarcodes join bridgeb on
substring(barcode,1,13) = bridgeb.barcodes


要么

select barcode, test from (
  select barcode, substring(barcode,1,13) as test from outerbarcodes
) as outerbarcodes join bridgeb on
outerbarcodes.test = bridgeb.barcodes

10-05 20:11