很难的问题,很少有人做的出的,请大家帮帮忙!

xiaoyuer819 2003-04-07 12:03:47
我想用sql语句完成:前面的select语句含有7个字段,后面的select语句含有5个字段,我先让这些记录合在一起,其中两者的前5个字段的类型相同,我想在合并的时候后面的select语句含有5个字段后面增加两个字段,且记录内容为空,不字段该如何实现?
...全文
20 点赞 收藏 20
写回复
20 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ian2000 2003-04-09
decode() 的返回值是什么?!
回复
zhxylgh 2003-04-09
zz
回复
erp2 2003-04-07
不会吧?这么简单的问题居然说难?????????你的分太多了吧?

select 7个字段 from ....
union all
select 5个字段,'' as 7个字段的不同之一,'' as 7个字段的不同之二 from .....


强烈希望霉国和沙耷牧这两条狗长久咬下去。
预练次功必先自宫,
即使自宫未必成功,
若不自宫也可成功。
哈哈.............
http://www.3rcn.com
论坛从现在开始允许注册用户发贴子了.
http://www.3rcn.com/guest/index.asp
是中国人你就看看看看!!!
印尼如此对待华人,强烈建议中国政府出兵印尼,实行军事占领.
http://tf.xiloo.com/kan.htm
回复
j9988 2003-04-07
select 7个字段 from ....
union all
select 5个字段,null,null from .....
回复
xiaoyuer819 2003-04-07
help
回复
frisky 2003-04-07
up
回复
ian2000 2003-04-07
decode() 的返回值是什么?
回复
xiaoyuer819 2003-04-07
ian2000(粗人) 这个是没有问题的,肯定是其他的问题
回复
ian2000 2003-04-07
abc.e不在select中,不能order by abc.e
回复
xiaoyuer819 2003-04-07
出错信息:
不支持此接口 ORA-01790: expression must have same datatype as corresponding expression
回复
xiaoyuer819 2003-04-07
XLYT(雨田) 写的还是出错
回复
XLYT 2003-04-07
sql=" select abc.a,abc.b,abc.c,abc.d,abc.h ,abc.f from"
sql=sql+" ( select t3005.p_code as a,"
sql=sql+" t3017.c_name as b,"
sql=sql+" t3020.rank_name as c,"
sql=sql+" t3005.fly_hours as d,"
sql=sql+" t3020.rank_no as e,"
sql=sql+" t3005.flight_date as f,"
sql=sql+" T3035.EXAM_DATE as g , decode(T3035.RESULT, '1', '已完成', '2', '未通过', '--') as h "
sql=sql+" from t3005,"
sql=sql+" t3017,t3035,"
sql=sql+" t3020"
sql=sql+" where (t3005.crew_link_line='" & crew_link & "') and "
sql=sql+" (t3005.p_code=t3017.p_code) and "
sql=sql+" (t3005.p_code=t3035.p_code) and "
sql=sql+" (t3005.flight_date=t3035.EXAM_DATE) and "
sql=sql+" (t3005.rank_no=t3020.rank_no) and "
sql=sql+" (To_Char(t3005.flight_date,'YYYY-MM-DD')='" & sDay & "')"
sql=sql+" union all "
sql=sql+" select t3016.p_code as a,"
sql=sql+" t3017.c_name as b,"
sql=sql+" t3020.rank_name as c,"
sql=sql+" t3016.fly_hours as d,"
sql=sql+" t3020.rank_no as e,"
sql=sql+" t3016.flight_date as f, null as g , null as h "
sql=sql+" from t3016,"
sql=sql+" t3017,"
sql=sql+" t3020 "
sql=sql+" where (t3016.stew_link_line='" & stew_link & "') and "
sql=sql+" (t3017.p_code=t3016.p_code) and "
sql=sql+" (t3020.rank_no=t3016.rank_no) and "
sql=sql+" (To_Char(t3016.flight_date,'YYYY-MM-DD')='" & sDay & "') ) abc"
sql=sql+" order by abc.e"
回复
xiaoyuer819 2003-04-07
abc.e不就是t3020.rank_no
回复
zjcxc 2003-04-07
把SQL的最终结果贴出来.应该有点问题
回复
ian2000 2003-04-07
其实,第一句select用不着,只要最后order by e就可以了。
回复
ian2000 2003-04-07
abc.e不存在啊。
回复
ian2000 2003-04-07
把全部sql贴上来,应该不是字段不同的错。
回复
xiaoyuer819 2003-04-07
错在哪里?

sql=" select abc.a,abc.b,abc.c,abc.d,abc.h ,abc.f from"
sql=sql+" ( select t3005.p_code a,"
sql=sql+" t3017.c_name b,"
sql=sql+" t3020.rank_name c,"
sql=sql+" t3005.fly_hours d,"
sql=sql+" t3020.rank_no e,"
sql=sql+" t3005.flight_date f,"
sql=sql+" T3035.EXAM_DATE g , decode(T3035.RESULT, '1', '已完成', '2', '未通过', '--') h "
sql=sql+" from t3005,"
sql=sql+" t3017,t3035,"
sql=sql+" t3020"
sql=sql+" where (t3005.crew_link_line='" & crew_link & "') and "
sql=sql+" (t3005.p_code=t3017.p_code) and "
sql=sql+" (t3005.p_code=t3035.p_code) and "
sql=sql+" (t3005.flight_date=t3035.EXAM_DATE) and "
sql=sql+" (t3005.rank_no=t3020.rank_no) and "
sql=sql+" (To_Char(t3005.flight_date,'YYYY-MM-DD')='" & sDay & "')"
sql=sql+" union all "
sql=sql+" select t3016.p_code a,"
sql=sql+" t3017.c_name b,"
sql=sql+" t3020.rank_name c,"
sql=sql+" t3016.fly_hours d,"
sql=sql+" t3020.rank_no e,"
sql=sql+" t3016.flight_date f, null g , null h "
sql=sql+" from t3016,"
sql=sql+" t3017,"
sql=sql+" t3020 "
sql=sql+" where (t3016.stew_link_line='" & stew_link & "') and "
sql=sql+" (t3017.p_code=t3016.p_code) and "
sql=sql+" (t3020.rank_no=t3016.rank_no) and "
sql=sql+" (To_Char(t3016.flight_date,'YYYY-MM-DD')='" & sDay & "') ) abc"
sql=sql+" order by abc.e"

回复
jeckwa 2003-04-07
select 字段(7个的) from ....
union
select 5个字段,''(0) as 7个字段中的另两个字段之一,''(0) as 7个字段的中的最后一个 from .....可要注意前一个Select的字段排列要与后面的字段排序顺序一样。
并且字段类型也要一样。
如果字段类型为数字之类的,可不能用''还要用0绝对不会错

回复
xiaoyuer819 2003-04-07
不对啊
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2003-04-07 12:03
社区公告
暂无公告