日期:2014-05-18  浏览次数:20692 次

如何得到一个用户在,在数据库的第一行数据
我的数据库里一个用户有很多的角色,例如用户A
ROLE                 NAME
  Q                       B
  E                       A
  R                       A
  F                       C
  D                       A
用户A有3个角色,我如何得到用户A的第一条记录,也就是ROLE为E的数据   谢谢

------解决方案--------------------
select ROLE from table where name = 'A ' order by role asc/desc limit 1
不能满足么? 不懂
<%=rs.getString( "ROLE ")%>
------解决方案--------------------
根据 ROLE 的升序排序 查找 NAME = A 的第一条记录就可以了
数据是 sql server 的话你就可以这样写
select top 1 role,name from table order by role

------解决方案--------------------
在oracle 中 select ROLE from table where name = 'A ' and rownum=1
在sqlservlet中select top 1 ROLE from table where name = 'A '