注册 登录
编程论坛 SQL Server论坛

新手求助一个简单的SQL语句,为什么我老是出错。。。

zhanxinlin 发布于 2010-05-19 12:51, 559 次点击
" border="0" />
请写出在class表中查找满足如下条件的记录的SQL语句:
1.返回字段 c_name,c_stu
2.返回记录数:前5条
3.查询条件:c_stu值大于30,并且c_type值为直,并且c_name字段值中有“二班”两个字
4.查询结果按c_stu正排序,按c_type倒排序(注:在正排序时请不要省略排序关键字)

为什么我写了
select top 5 c_name,c_stu from class where c_stu>30 and c_type=true and c_name="二班" order by c_stu asc,c_type desc
这条却提示错误呢。
5 回复
#2
aei1352010-05-19 13:11
数据库c_type值不能为true,应该为1或者0,二班也必须是单引号括起来,不能用双引号
select top 5 c_name,c_stu from class where c_stu>30 and c_type=1 and c_name like '二班%' order by c_stu asc,c_type desc
#3
zhanxinlin2010-05-19 13:28
建数据库实际测试中证明上面语句是可以正确执行的,但在一个动画教程里面出现的这个问题却都提示回答错误,不知错在哪里。呜呜 呜    有两个章节学不了。。。。回答不了问题没办法进去下个章节
#4
zhanxinlin2010-05-19 13:30
同时感谢版主及时的支持
#5
源本英明C2010-05-19 14:25
回复 楼主 zhanxinlin
或者可以这样:select top 5 c_name,c_stu from class where c_stu>30 and c_type=1 and c_name like '*%二班%' order by .........(同版主)。姓名的搜索更精确些!
#6
aei1352010-05-19 17:45
楼上笔误多了个*吧
1