发布网友 发布时间:2024-10-24 03:38
共2个回答
热心网友 时间:6分钟前
with A as(select distinct 人员 from 表名)
select 人员,大级_次数=(select top 1 次数 from 表名 B where B.人员=A.人员 and 级别='大' order by 计划日期 desc),
大级_计划日期=(select top 1 计划日期 from 表名 B where B.人员=A.人员 and 级别='大' order by 计划日期 desc),
中级_次数=(select top 1 次数 from 表名 B where B.人员=A.人员 and 级别='中' order by 计划日期 desc),
中级_计划日期=(select top 1 计划日期 from 表名 B where B.人员=A.人员 and 级别='中' order by 计划日期 desc),
小级_次数=(select top 1 次数 from 表名 B where B.人员=A.人员 and 级别='小' order by 计划日期 desc),
小级_计划日期=(select top 1 计划日期 from 表名 B where B.人员=A.人员 and 级别='小' order by 计划日期 desc)
from A
热心网友 时间:1分钟前
CREATE TABLE [dbo].[biao](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nchar](40) NULL,
[jibie] [nchar](10) NULL,
[num] [int] NULL,
[date] [datetime] NULL
) ON [PRIMARY]
select a.*,b.num,b.jibie,b.date,c.num,c.jibie,c.date from (select a.* from biao a left join (select name,max(date) dated from biao where jibie = '大' group by name) b on a.name=b.name where a.date=b.dated) a
left join (select a.num,a.jibie,a.date,a.name from biao a left join (select name,max(date) datez from biao where jibie = '中' group by name) b on a.name=b.name where a.date=b.datez)
b on a.name=b.name
left join (select a.num,a.jibie,a.date,a.name from biao a left join (select name,max(date) datex from biao where jibie = '小' group by name) b on a.name=b.name where a.date=b.datex)
c on a.name=c.name