请问这个SQL如何写,TKS

TGZ 2008-05-17 10:37:35
请问这个SQL如何写,谢谢!

初始:
T1 T2 T3
--------------
A 12 43
A MM MM
B XC ED
C DS XX
C ES EE

结果:

T1 T2 T3
--------------
A 12 43
MM MM
B XC ED
C DS XX
ES EE
...全文
70 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
TGZ 2008-05-17
  • 打赏
  • 举报
回复
TKS!!!
Limpire 2008-05-17
  • 打赏
  • 举报
回复
--> 测试数据: #T
if object_id('tempdb.dbo.#T') is not null drop table #T
create table #T (T1 varchar(1),T2 varchar(2),T3 varchar(2))
insert into #T
select 'A','12','43' union all
select 'A','MM','MM' union all
select 'B','XC','ED' union all
select 'C','DS','XX' union all
select 'C','ES','EE';

with T as
(
select id=row_number()over(partition by T1 order by T1),* from #T
)
select T1=case id when (select min(id) from T where T1=t.T1) then T1 else '' end, T2,T3 from T as t

/*
T1 T2 T3
---- ---- ----
A 12 43
MM MM
B XC ED
C DS XX
ES EE
*/
liangCK 2008-05-17
  • 打赏
  • 举报
回复
create table tb(t1 varchar(10),t2 varchar(10),t3 varchar(10))
insert into tb select 'A' , '12' , '43'
insert into tb select 'A' , 'MM' , 'MM'
insert into tb select 'B' , 'XC' , 'ED'
insert into tb select 'C' , 'DS' , 'XX'
insert into tb select 'C' , 'ES' , 'EE'
go

select t1=case when t2=(select min(t2) from tb where t1=a.t1) then t1 else '' end,
t2,t3
from tb a

go
drop table tb

/*
t1 t2 t3
---------- ---------- ----------
A 12 43
MM MM
B XC ED
C DS XX
ES EE

(所影响的行数为 5 行)

*/
asp动态页面经典实例 <% session.timeout=125 flag=0 set rs=conn.execute("select * from test order by examinationid desc ") if rs.eof then flag=1 response.write"

=========================== 暂无考试 ===========================

" session("qi")=0 pd=0 pds=0 xz=0 xzs=0 tk=0 tks=0 zfen=pd*pds+xz*xzs+tk*tks else set rss=conn.execute("select * from examination order by examinationid desc ") if rss.eof then session("qi")=1 else session("qi")=rss("examinationid")+1 end if pd=rs("rightorwrongid") pds=rs("rightorwrongscore") Response.Write rs("rightorwrongscore") xz=rs("selectid") xzs=rs("selectscore") tk=rs("fillingid") tks=rs("fillingscore") zfen=pd*pds+xz*xzs+tk*tks end if %> 网上考试系统

<%=session("student")%>,您好!

您将要参加的第 <%=session("qi")%> 期考试情况如下:

本期考试 <%=pd%> 道判断题,<%=xz%> 道选择题,<%=tk%> 道填空题,总分 <%=zfen%>

进入考试===>
 
   

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧