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  
相关文档:
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安装时报挂起错误
SQL server安装时时:“以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机”错误。 打开注册表编辑器(开始->运行->regedit),在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager中找到PendingFileRenameOperations项目,并删 ......
常用SQL查询:
1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
2、查看表空间物理文件的名称及大小
select tablespace_name, file_id, ......
use Tempdb
go
if object_ID ( 'fn_ACITEncryption' ) is not null
drop function fn_ACITEncryption
go
create function fn_ACITEncryption
(
@Str nvarchar ( 4000), -- 加密的字符串
@Flag bit = 1, --1 、加密 0 、解密
@Key nvarchar ( 50) -- 密文
)
returns nvarchar ( 4000) ......