繁体   English   中英

SQL SELECTING *,然后从以结尾的列中选择值

[英]SQL SELECTING * then select values from columns that end with

我有以下代码;

Select * from test left join testtwo on test.testid = testtwo.id

然后,我需要从“ testtwo”的另一个称为“ code”的列中选择值,并且这些值以“ 100”('%100')结尾

我尝试了以下代码,但是没有用:

Select * from test left join testtwo on test.testid = testtwo.id
union
SELECT * FROM testtwo
WHERE code LIKE '100%';

id    testid   code
1     1       0001100
2     2       0002100
3     3       0003100
4     4       0004100

对于值以100结尾的字符串列,应使用

 WHERE code LIKE '%100'; 

寻找您可以使用的样品

Select * 
from test 
INNER  join testtwo on test.testid = testtwo.id
WHERE code LIKE '%100';

如果还需要'%400',则可以使用OR条件

Select * 
from test 
INNER  join testtwo on test.testid = testtwo.id
WHERE code LIKE '%100' 
OR code LIKE '%400' ;

或使用工会

Select * 
from test 
INNER  join testtwo on test.testid = testtwo.id
WHERE code LIKE '%100' 
union 
Select * 
from test 
INNER  join testtwo on test.testid = testtwo.id
WHERE code LIKE '%400' 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM