关于SQL语言的问题?请高手指教

来源:百度知道 编辑:UC知道 时间:2024/04/28 16:51:21
我想在一个表stud中查询一个所有男生,然后在所有男生中查询叫李明的人怎么实现呢?
我这样用
select * from (select * from stud where sex like "男" ) where name like "李明"
但是报错“select子函数错误”
请高手指点!谢谢!

like 后面的条件不对
select * from (select * from stud where sex like '%男%' ) where name like '%李明%'

select * from (select * from stud where sex like '男' )a where [name] like '%李明%'

或 select * from stud where [name] like '%李明%' and sex='男'

select * from stud where sex="男" as view1
select * from view1 where name="李明"
就是要建立一个视图 在从视图里查询 具体视图建立的方法不记得了

select * from stud where name like “李明” and sex=“男”

like 条件的 字符 要用 单引号''不应该有“” ,%写不写看情况,还有字段一样的情况下,最好使用别名,否则不注意会出错。不过,这个不使用别名应该也没问题。