
SQLSERVER的问题.在线等,追加分..
先有表T1,字段A1(统计),A2(人数),A3(国别),A4(次数),M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12(M1-M12表示12...
先有表T1,字段A1(统计),A2(人数),A3(国别),A4(次数),M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12
(M1-M12表示12个月不能重复)
我希望查询出来的结果是:
A1 M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12
A2
A3
A4
A2,A3,A4的数据对应在M1-M12.
麻烦写下完整的语句啊..
问题我自己已经解决了.谢谢大家了. 展开
(M1-M12表示12个月不能重复)
我希望查询出来的结果是:
A1 M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12
A2
A3
A4
A2,A3,A4的数据对应在M1-M12.
麻烦写下完整的语句啊..
问题我自己已经解决了.谢谢大家了. 展开
5个回答
展开全部
你好,我为测试就随便建了个表,在我这可以查出,但不知道是不是你要的效果,你看下create table txt_person
(
pID int primary key identity(1,1),
pmonth varchar(20),--月份
pnum int default 1,--次数
pcountry varchar(20),--国别
pcol int--人数
)
insert into txt_person(pmonth,pcountry, pcol) select pmonth, pcountry,pcol from txt_person --values('中国',2)
insert into txt_person(pmonth,pcountry, pcol) values('六月','美国',2)
select * from txt_person
select pmonth, sum(pnum) as 次数,pcountry,sum(pcol) as 人数 from txt_person group by pmonth,pcountry
(
pID int primary key identity(1,1),
pmonth varchar(20),--月份
pnum int default 1,--次数
pcountry varchar(20),--国别
pcol int--人数
)
insert into txt_person(pmonth,pcountry, pcol) select pmonth, pcountry,pcol from txt_person --values('中国',2)
insert into txt_person(pmonth,pcountry, pcol) values('六月','美国',2)
select * from txt_person
select pmonth, sum(pnum) as 次数,pcountry,sum(pcol) as 人数 from txt_person group by pmonth,pcountry
展开全部
用union all实现:
select A1,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1
union all
select A2,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1
union all
select A3,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1
union all
select A4,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1;
---
以上,希望对你有所帮助。
select A1,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1
union all
select A2,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1
union all
select A3,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1
union all
select A4,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12 from T1;
---
以上,希望对你有所帮助。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select A1,count(M1) as M1,......... from table group by A1
这样?
这样?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
secelt A1,M1 ,M2 ,M3 ,M4 ,M5 ,M6, M7, M8, M9 ,M10 ,M11, M12 from T1
go
secelt A2,M1 ,M2 ,M3 ,M4 ,M5 ,M6, M7, M8, M9 ,M10 ,M11, M12 from T1
go
secelt A3,M1 ,M2 ,M3 ,M4 ,M5 ,M6, M7, M8, M9 ,M10 ,M11, M12 from T1
go
secelt A4,M1 ,M2 ,M3 ,M4 ,M5 ,M6, M7, M8, M9 ,M10 ,M11, M12 from T1
go
go
secelt A2,M1 ,M2 ,M3 ,M4 ,M5 ,M6, M7, M8, M9 ,M10 ,M11, M12 from T1
go
secelt A3,M1 ,M2 ,M3 ,M4 ,M5 ,M6, M7, M8, M9 ,M10 ,M11, M12 from T1
go
secelt A4,M1 ,M2 ,M3 ,M4 ,M5 ,M6, M7, M8, M9 ,M10 ,M11, M12 from T1
go
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先count(*),然后group by 月份,貌似挺难啊!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询