SQL与Like运算符联接
我有这样的桌子 表格用户:SQL与Like运算符联接,sql,sql-server,sql-server-2012,Sql,Sql Server,Sql Server 2012,我有这样的桌子 表格用户: id | name -----+------------ 1 | John Smith 2 | Maria 3 | peter 诉状 id | ComplaintIssue | User -----+------------------+----- 1 | Isssue1 | 1 2 | Issue nth | 3 3 | Issue infinity | 4 现在我尝试从
id | name
-----+------------
1 | John Smith
2 | Maria
3 | peter
诉状
id | ComplaintIssue | User
-----+------------------+-----
1 | Isssue1 | 1
2 | Issue nth | 3
3 | Issue infinity | 4
现在我尝试从下面的查询中获取输出
select
tc.id, tc.complaintissue, tu.name tc
from
tablecomplaint tc
join
tbuser tu on tu.id = tc.user
where
tc.comlaintissue like '%%' or tu.name like '%%'
但我无法在tu.name
上设置like运算符
我希望允许我的输出查询也使用用户名进行搜索。您的“tc”出现两次
select tc.id, tc.complaintissue, tu.name [->]tc from tablecomplaint [->] tc
join tbuser tu on tu.id = tc.user
where tc.comlaintissue like '%%' or tu.name like '%%'
你想说什么
select tc.id, tc.complaintissue, tu.name from tablecomplaint tc
join tbuser tu on tu.id = tc.user
where tc.comlaintissue like '%%' or tu.name like '%%'
“tc”出现两次
select tc.id, tc.complaintissue, tu.name [->]tc from tablecomplaint [->] tc
join tbuser tu on tu.id = tc.user
where tc.comlaintissue like '%%' or tu.name like '%%'
你想说什么
select tc.id, tc.complaintissue, tu.name from tablecomplaint tc
join tbuser tu on tu.id = tc.user
where tc.comlaintissue like '%%' or tu.name like '%%'
它起作用了
select
tc.id, tc.complaintissue, tu.name tc
from
tablecomplaint tc
join
tbuser tu on tu.id = tc.user
where
tc.complaintissue like '%%' or tu.name like '%%'
它起作用了
select
tc.id, tc.complaintissue, tu.name tc
from
tablecomplaint tc
join
tbuser tu on tu.id = tc.user
where
tc.complaintissue like '%%' or tu.name like '%%'
您的sql在我看来很好(除了where子句中投诉一词的拼写错误)。什么不起作用?名称的数据类型是什么?某些类型不能与
LIKE
运算符一起使用。这意味着什么:“我不能将LIKE运算符放在tu.name上”?tc.name tc从表中投诉tc
是错误的,就像where tc.comlaintisue
一样。阅读您正在编写的SQL以及收到的错误消息。我觉得您的SQL很好(除了where子句中投诉一词的拼写错误)。什么不起作用?名称的数据类型是什么?某些类型不能与LIKE
运算符一起使用。这意味着什么:“我不能将LIKE运算符放在tu.name上”?tc.name tc从表中投诉tc
是错误的,就像where tc.comlaintisue
一样。阅读您正在编写的SQL以及收到的错误消息。