请帮忙看下这个sql查询语句

来源:百度知道 编辑:UC知道 时间:2024/05/26 21:44:26
我要编写一个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=ture and c_name like '*二班*' order by c_stu asc,c_type desc
好像是错的,不知道怎么改,请大家帮帮忙!谢谢

如果是ACCESS数据库:

select top 5 c_name,c_stu from [class] where c_stu>30 and c_type=ture and c_name like '%二班%' order by c_stu asc,c_type desc;

如果是SQL Server数据库:

1.c_type是字符串类型

select top 5 c_name,c_stu from [class] where c_stu>30 and c_type='ture' and c_name like '%二班%' order by c_stu asc,c_type desc;

2.c_type是bit类型(1表是true,0表示false)

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;

没什么问题,只不过如果不是access数据库的话,应该把'*二班*'换成'%二班%'

是不是应该吧c_name like '*二班*' 中的 * 号改为 % 号啊。你试试看