现有3个表
a 表示查看记录 b 表示下载记录 c表示邀请记录
要把3个表数据查询出来来整合到一个表里显示 每条记录还得有个状态(查看,下载,邀请),,,,,这个状态每个表里没有字段的
请高手简单知道下 帮我写个主体框架
a 表示查看记录 b 表示下载记录 c表示邀请记录
要把3个表数据查询出来来整合到一个表里显示 每条记录还得有个状态(查看,下载,邀请),,,,,这个状态每个表里没有字段的
请高手简单知道下 帮我写个主体框架
--如果表结构一样,不一样自己改下成一样的
select *,'查看' from a
union all
select *,'下载' from b
union all
select *,'邀请' from c
select '查看' as type,* from a
union all
select '下载',* from b
union all
select '邀请',* from c
)t
union all
select *,'下载' as flag from b
union all
select *,'邀请' as flag from c
from 查看记录
union all
select ...,'下载' as 状态
from 下载记录
union all
select ...,'邀请' as 状态
from 邀请记录
select *,'查看' as '状态' from a --第一次每个列都要加个列名,*里的自己看情况改
union all
select *,'下载' from b
union all
select *,'邀请' from c
union all
select *,'下载' from b
union all
select *,'邀请' from c
楼主,若你的表的结构相同,可以使用unio all 连接查询:
select *,'查看' as '状态' from 表名
union all
select *,'下载' from 表名
union all
select *,'邀请' from 表名