我正在使用sql ...我的表名为Table1,有2列:column1和column2。首先,我需要选择第1列包含“andrew”或“brandon”的两列。然后我想在column2中进行比较,并返回与column2中的字段类似的字符串的结果。
column1 column2
andrew hi
brandon hello
andrew hello
carl hi
返回:
brandon hello
andrew hello
答案 0 :(得分:1)
由于你想比较两行,没有JOIN或子查询就无法真正逃脱。如果我理解正确,这应该在“任何数据库”SQL中执行您想要的操作;
SELECT t1a.*
FROM Table1 t1a
JOIN Table1 t1b
ON t1a.column2 = t1b.column2 AND t1a.column1 <> t1b.column1
WHERE t1a.column1 in ('andrew', 'brandon') AND
t1b.column1 IN ('andrew', 'brandon');
演示here。
答案 1 :(得分:0)
尝试以下查询:
SELECT column1+' '+ column2 from Table1 where column1 IN ('andrew','brandon')