首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

sql语句有关问题,求解,

2013-01-11 
sql语句问题,求解,急!!select mail,nickname from newregister where nickname in (select name from cust

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.

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

热点排行