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

SQL 每个分类各取2条数据

create table tb (ptoid int,proclassid int,proname varchar(10))
insert tb
select 1,1,'衣服1'
union all
select 2,2,'衣服2'
union all
select 3,3,'衣服3'
union all
select 4,3,'衣服4'
union all
select 5,2,'衣服5'
union all
select 6,2,'衣服6'
union all
select 7,2,'衣服7'
union all
select 8,1,'衣服8'
select * from tb
ptoid       proclassid  proname   
----------- ----------- ----------
1           1           衣服1
2           2           衣服2
3           3           衣服3
4           3           衣服4
5           2           衣服5
6           2           衣服6
7           2           衣服7
8           1           衣服8
(所影响的行数为 8 行)
select * from tb a where
(select count(*) from tb b where b.proclassid=a.proclassid and b.ptoid>a.ptoid) <2
order by proclassid
ptoid       proclassid  proname   
----------- ----------- ----------
1           1           衣服1
8           1   


相关文档:

MyEclipse5.5下连接Sql Server 2008的方法

下面是指导文档。请跟着一步步的做。就能成功连接上sql server 2008
 
java中连接sql server 2008的注意事项:
2000,2005的数据库驱动类的写法是:
com.microsoft.jdbc.sqlserver.SQLServerDriver
URL的写法是:假设数据库是news
jdbc:microsoft:sqlserver://localhost:1433;databaseName=news
 
但是20 ......

怎么把 sql语句查询的值赋给变量

string str = System.Configuration.ConfigurationManager.AppSettings["strconn"];
string sqlpwd = "select password from bg_user where username='" + username + "'";
MySqlConnection conn = new MySqlConnection(str);
MySqlCommand cmd=new MySqlCommand(sqlpwd,conn);
MySqlDataAdapter adr = new MySqlDataA ......

SQL Server 2005 不允许远程连接解决方法

SQL Server 2005 不允许远程连接解决方法
 
刚刚安装的数据库系统,按照默认安装的话,很可能在进行远程连接时报错,通常是错误:"在连接到 SQL Server 2005 时,
在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。
(provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) "搜M ......

sql之left join、right join、inner join的区别

left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
inner join(等值连接) 只返回两个表中联结字段相等的行
举例如下:
--------------------------------------------
表A记录如下:
aID     aNum
1     a ......

sql中的分段列表

表:用户号码,登录时间
显示 :每日登录各时间段的登录人数,和每天登录人数
if isnull(object_id('#tb'),'')=''
drop table #tb
CREATE TABLE #tb(列名1 varchar(12),时间 datetime)
INSERT INTO #tb
SELECT '03174190188','2009-11-01 07:17:39.217' UNION ALL
SELECT '015224486575','2009-11-01 08:01:17.153' ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号