sql里的一条查询语句

来源:百度知道 编辑:UC知道 时间:2024/05/21 04:17:06
在sql2000 个人版中学习sql:老师的例题中有:
select * from tea where (年龄,职称) = (select 年龄,职称 from tea where 姓名='王强')
意思是找出和王强年龄职称一样的其他人。
但是输入后,提示逗号附近有语法错误。
检查若干遍后,实在是发现不了错误。请教。
lackyhuang - 高级经理 六级 的回答,输入语句后,结果整个表都返回了
杀·破狼 - 江湖新秀 四级 的回答,我也觉的讲课的老师错了,不过人家是大家,无奈只好求助于各位。

语法都错了。。
正确的写法:
select * from tea where 年龄=(select 年龄 from tea where 姓名='王强') and 职称=(select 职称 from tea where 姓名='王强')

你的逗号是不是英文格式的??我也学SQL不久,不知道是不是这方面的错误,你试一下吧。

select * from tea where (年龄,职称) in (select 年龄,职称 from tea where 姓名='王强')

你这个where语句写的有毛病,
年龄 和职称,要么写2条
年龄= () 职称=()

要么就写其中的一个

select * from tea where exists
(select 年龄,职称 from tea where 姓名='王强')

请看脚本:

select a.* from tea a,
(select 年龄,职称 from tea where 姓名='王强') b where
a.年龄=b.年龄
and a.职称=b.职称