
例如:
select 表1.组名,
(select 表1.成员姓名 from 表2 b where 表1.成员1id=表2.成员id) as 成员1id,
(select 表1.成员姓名 from 表2 b where 表1.成员2id=表2.成员id) as 成员2id,
(select 表1.成员姓名 from 表2 b where 表1.成员3id=表2.成员id) as 成员3id
from 表1,表2
--这种就是交叉表查询
select 地区名称 地区,month(日期)+'月'+day(日期)+'日' 日期,sum(case when year(日期)=2010 then 日销量 end) 2010年,
sum(case when year(日期)=2011 then 日销量 end) 2011年,
sum(case when year(日期)=2012 then 日销量 end) 2012年,
sum(case when year(日期)=2013 then 日销量 end) 2013年
from 销量表,地区表
where 销量表.地区id=地区表.id
group by 地区,month(日期)+'月'+day(日期)+'日'
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)