日期:2014-05-17  浏览次数:20931 次

sql语句问题,求解,急!!
select mail,nickname from newregister where nickname in (select name from custom1 where company = '"+lbl_com_cn.Text+"')。
第一行是top 1
如何取第二行,第三行数据呢?
select top 2 from xxx where not in (select top 1 from xxx)这如何嵌套进去呢?

求大神解答

------解决方案--------------------
用row_number()也许好处理一些
------解决方案--------------------
SELECT *, Row_Number() OVER (partition by nickname  ORDER BY mail desc) as rownum, mail,nickname from newregister where nickname in (select name from custom1 where company = '"+lbl_com_cn.Text+"')
where rownum=1;2;3;.....
------解决方案--------------------

Select * From (Select Row_Number() Over(Order by Id desc) as row,* from xxx where ....) T Where T.row Between 1 and 2

------解决方案--------------------
引用:
有人会用select top 2  not in select top 1么?求更改啊

什么?

select top 1 from xxx where name  not in (select top 1 name  from xxx)
------解决方案--------------------
可用
public static DataTable SelectPage(int pageStart, int pageSize, string SqlString)
        {
            SqlDataAdapter Adapter = new SqlDataAdapter();
            DataTable Table = new DataTable();
            using (SqlConnection connetion = new SqlConnection(connectionString))
            {
                Adapter.SelectCommand = new SqlCommand(SqlString, connetion);
                Adapter.Fill(pageStart, pageSize, Table);
                return Table;
            }
        }

------解决方案--------------------
教你一个很灵活的语句:
select * from 
    {
        select Row_Number()  over(Order by (xx)Fsalary Desc) as rownum,(xx)Fnumber from T_Employee as e
    }
    
where e.rownum >= 5 and e.rownum <= 8.

连范围都可以取,
就是子查询!这是例子,具体我也不知道你的需求!