22,301
社区成员




CREATE TABLE [tb]
(
[编号] VARCHAR(10) NULL ,
[价格] VARCHAR(10) NULL ,
[供应商] varchar(100) NULL
)
GO
INSERT INTO [tb] ([编号],[价格],[供应商])
SELECT '01','1.15','供应商A' UNION
SELECT '02','1.1','供应商A' UNION
SELECT '02','1.1','供应商G' UNION
SELECT '03','1.3','供应商A' UNION
SELECT '04','1.2','供应商A'
GO
select 编号 , 价格 , min(供应商) 供应商 from tb group by 编号 , 价格 order by 编号 , 价格
drop table tb
/*
编号 价格 供应商
---------- ---------- ----------------------------------------------------------------------------------------------------
01 1.15 供应商A
02 1.1 供应商A
03 1.3 供应商A
04 1.2 供应商A
(所影响的行数为 4 行)
*/
--上一条新闻
select top 1 * from tb where id < 5 order by id desc
--下一条新闻
select top 1 * from tb where id > 5 order by id
if (myListDs.Tables[0].Rows.Count > 0)
{
if (myListDs.Tables[0].Rows.Count == 1)
{
paramPritID = "";
paramPritTitle = "";
paramNextID = "";
paramNextTitle = "";
}
else
{
for (int i = 0; i < myListDs.Tables[0].Rows.Count; i++)
{
if (Request["id"].Length > 0)
{
if (myListDs.Tables[0].Rows[i]["id"].ToString() == Request["id"])
{
if ((i - 1) < 0)
{
paramPritID = "";
paramPritTitle = "";
}
else
{
paramPritID = myListDs.Tables[0].Rows[i - 1]["id"].ToString();
paramPritTitle = myListDs.Tables[0].Rows[i - 1]["title"].ToString();
}
if ((i + 1) >= myListDs.Tables[0].Rows.Count)
{
paramNextID = "";
paramNextTitle = "";
}
else
{
paramNextID = myListDs.Tables[0].Rows[i + 1]["id"].ToString();
paramNextTitle = myListDs.Tables[0].Rows[i + 1]["title"].ToString();
}
}
}
else
{
if ((i - 1) < 0)
{
paramPritID = "";
paramPritTitle = "";
}
else
{
paramPritID = myListDs.Tables[0].Rows[i - 1]["id"].ToString();
paramPritTitle = myListDs.Tables[0].Rows[i - 1]["title"].ToString();
}
if ((i + 1) >= myListDs.Tables[0].Rows.Count)
{
paramNextID = "";
paramNextTitle = "";
}
else
{
paramNextID = myListDs.Tables[0].Rows[i + 1]["ID"].ToString();
paramNextTitle = myListDs.Tables[0].Rows[i + 1]["title"].ToString();
}
}
}
}
}
else
{
paramPritID = "";
paramPritTitle = "";
paramNextID = "";
paramNextTitle = "";
}