麻烦问一下 我写了一个查询select * from cc where hm='123456'
我查出来里面有几个结果
hm mc jine
123456 白菜 12.00但是我2个表连个查询的时候
select hm,mc,jine from (
select hm,mc,jine from cc where hm='123456'
union
select hm,mc,jine from bb where hm='123456'
)
bb表里面是没有的
这个这个查询结果查出来的时候
hm mc jine
123456 白菜 12金额变成12了 不是12.00了 这个是怎么回事啊?
怎么保持12.00???
谢谢
我查出来里面有几个结果
hm mc jine
123456 白菜 12.00但是我2个表连个查询的时候
select hm,mc,jine from (
select hm,mc,jine from cc where hm='123456'
union
select hm,mc,jine from bb where hm='123456'
)
bb表里面是没有的
这个这个查询结果查出来的时候
hm mc jine
123456 白菜 12金额变成12了 不是12.00了 这个是怎么回事啊?
怎么保持12.00???
谢谢
select hm,mc,to_char(jine,99999.99) from (
select hm,mc,jine from cc where hm='123456'
union
select hm,mc,jine from bb where hm='123456'
)
select hm,mc,to_char(jine,99999.99) from (
select hm,mc,jine from cc where hm='123456'
union
select hm,mc,jine from bb where hm='123456'
)
这样写的时候 一直不能在执行 很久都没结束
我查出来里面有几个结果
hm mc jine
123456 白菜 12.00但是我2个表连个查询的时候
select hm,mc,jine from (
select hm,mc,jine from cc where hm='123456'
union
select hm,mc,jine from bb where hm='123456'
union
select hm,mc,jine from aa where hm='123456'
)
比如bb,cc表里面是没有的
这个这个查询结果查出来的时候
hm mc jine
123456 白菜 12金额变成12了 不是12.00了 这个是怎么回事啊?
怎么保持12.00???后来我发aa,bb,cc三张表 的jine这个字段 有些是num 有些是varchar不一样
联合查询后 jine这个字段都统一成varchar类型了这种的话 我不是让他保留小数点后面2位
而是要他联合查询的时候 jine查询出来是什么类型就是什么类型因为要是我用用to_char(jine,‘999999.99’)
这种的话 查出来始终要保留小数点后面2位
我不是要让他保留 而是想查出来是什么类型就是什么类型
select hm,mc,to_number(jine) jine from cc where hm='123456'
union
select hm,mc,to_number(jine) jine from bb where hm='123456'
union
select hm,mc,to_number(jine) jine from aa where hm='123456'
)
select hm,mc,jine from (
select hm,mc,jine from cc where hm='123456'
union
select hm,mc,jine from bb where hm='123456'
union
select hm,mc,jine from aa where hm='123456'
)括号里的子查询因为jine在aa,bb表里的字段是number型,但cc是char型,所以cc里的字段jine会自动转换成number型,如果你想要保持查询结果一至的话,最好把aa,bb里的jine字段转成varchar类型。