关于SQl语句的问题 求大神解答
select Applicant_name,HEAD_name,SIGN_name from
(
select hum_list.first_name Applicant_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.Applicant
union all
select hum_list.first_name HEAD_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.HEAD
union all
select hum_list.first_name SIGN_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.Sign
)
运行报错:"SIGN_name"标识符无效
select * from
(
select hum_list.first_name Applicant_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.Applicant
union all
select hum_list.first_name HEAD_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.HEAD
union all
select hum_list.first_name SIGN_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.Sign
)
运行无错误 但是我需要Applicant_name,HEAD_name,SIGN_name 三个字段 运行结果只有Applicant_name一个字段
请教各大神应该怎么改
[解决办法]
select a.Applicant_name,a.HEAD_name,a.SIGN_name from
(
select hum_list.first_name Applicant_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.Applicant
union all
select hum_list.first_name HEAD_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.HEAD
union all
select hum_list.first_name SIGN_name from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.Sign
) a
with ResultData as
{
select hum_list.first_name Applicant_name,hum_list.first_name HEAD_name,hum_list.first_name SIGN_name
from hum_list,s_zhgl_Send_meal where hum_list.human_id=s_zhgl_Send_meal.Applicant and
hum_list.human_id=s_zhgl_Send_meal.HEAD and hum_list.human_id=s_zhgl_Send_meal.Sign
//and 你试试行不行不行改成or试试 然后看看需不需要加group by
}
select Applicant_name,HEAD_name,SIGN_name from ResultData //看看需不需要加group by