易截截图软件、单文件、免安装、纯绿色、仅160KB

sql查询结果排序问题 - MS-SQL Server / 基础类

sql 查询结果排序问题
先查出来的放在表前面

 比如:搜索关键字 :'北京 高考'
1。查询结果 同时 匹配 “北京”“高考”
select * from News where Title like '%北京%' and ''Title like '%高考%'
2。匹配一个关键字 
select * from News where Title like '%北京%' or ''Title like '%高考%'

问题:我要把同事匹配 北京 高考 的放在最前面,



SQL code:
select (case when Title like '%北京%' then 1
when Title like '%高考%' then 2
when Title like '%北京%' and ''Title like '%高考%' then 0
else 3 end) o,*
from News where Title like '%北京%' and ''Title like '%高考%'
order by o


试试看
SQL code:
select * from News
where (Title like '%北京%' and Title like '%高考%')
or Title like '%北京%' or Title like '%高考%'
order by case when (Title like '%北京%' and Title like '%高考%') then 0 else 1 end


SQL code:
select
(case when Title like '%北京%' then 1
when Title like '%高考%' then 2
when Title like '%北京%' and Title like '%高考%' then 0
else 3 end) o,*
from News where Title like '%北京%' and ''Title like '%高考%'
order by o



相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

SQL如何优化问题 - MS-SQL Server / 疑难问题

今天做了一个存储过程   环境是SQL2000数据库  
大致如下
建立临时表
定义员工游标
        循环员工(属于1个公司)  
        ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......

sql 多表统计问题 - MS-SQL Server / 应用实例

表A
  日期 支出金额 
  2010-04-01 120
  2010-04-02 250
  2010-05-01 100 
  2010-05-04 200
  2010-05-06 300
表B
  日期 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号