是SQL的BUG吗?大侠看看到底是怎么回事

y740504 2008-02-11 05:41:08
第一条:select amount_in from stocks_inout_jz where amount_in>0 and month_jz='2008年02月'
第二条:select sum(amount_in) from stocks_inout_jz where month_jz='2008年02月'

我执行上面的语句,出现如下结果:
第一条语句是空语句,但是第二条语句返回的值却时:28823037615171174.40为何呀?
...全文
1348 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
victorcai2006 2008-02-24
  • 打赏
  • 举报
回复
MARK
  • 打赏
  • 举报
回复
select amount_in from stocks_inout_jz where month_jz='2008年02月' order by amount_in 看看表里前面和后面的数据你就明白了的.
JiangHongTao 2008-02-21
  • 打赏
  • 举报
回复
declare @t table(dd numeric(38,2))
declare @i int
set @i = 1
while @i <10
begin
insert @t select -987654321098765432109876543210987654.12
set @i = @i +1
end
select * from @t
select sum(dd) sum from @t
/*
服务器: 消息 8115,级别 16,状态 2,行 10
将 expression 转换为数据类型 numeric 时发生算术溢出错误。
*/
JiangHongTao 2008-02-21
  • 打赏
  • 举报
回复
不是负值溢出!
declare @t table(dd numeric(12,2))
declare @i int
set @i = 1
while @i <10
begin
insert @t select -9876543210.12
set @i = @i +1
end
select sum(dd) sum from @t
/*
sum
----------------------------------------
-88888888891.08
*/

declare @t table(dd numeric(38,2))
declare @i int
set @i = 1
while @i <10
begin
insert @t select -98765432109876543210987654321098765432.12
set @i = @i +1
end
select sum(dd) sum from @t
/*
服务器: 消息 1007,级别 15,状态 1,行 6
数字 '98765432109876543210987654321098765432.12' 超出了数字表示范围(最大精度为 38 位有效数字)。
*/
yyszh 2008-02-21
  • 打赏
  • 举报
回复
负值溢出!
todouwang 2008-02-19
  • 打赏
  • 举报
回复
是数据类型的问题,numeric(12,2)不够存放28823037615171174.40这样的大类型,会溢出的,你可以用numeric(38,2)替换
AlphaGroup 2008-02-16
  • 打赏
  • 举报
回复
第一条:select amount_in from stocks_inout_jz where amount_in> 0 and month_jz='2008年02月'
第二条:select sum(amount_in) from stocks_inout_jz where month_jz='2008年02月'

都改成
select *
检查一下输出数据就知道了。
wanglv 2008-02-13
  • 打赏
  • 举报
回复
1、仔细检查 month_jz,amount_in的数据类型,和两个字段中值的问题;
2、select amount_in from stocks_inout_jz where month_jz='2008年02月' order by amount_in desc 进行测试下
ojuju10 2008-02-13
  • 打赏
  • 举报
回复

还有可能为NULL
zefuzhang2008 2008-02-13
  • 打赏
  • 举报
回复
你的数据库有负值吧,2个语句条件不一样
ojuju10 2008-02-13
  • 打赏
  • 举报
回复

第一条:select amount_in from stocks_inout_jz where amount_in> 0 and month_jz='2008年02月'
第二条:select sum(amount_in) from stocks_inout_jz where month_jz='2008年02月'

两句的条件不一样啊

第二条:select sum(amount_in) from stocks_inout_jz where month_jz='2008年02月'
等价于

select amount_in from stocks_inout_jz where (amount_in<= 0 or amount_In is null) and month_jz='2008年02月'


ojuju10 2008-02-13
  • 打赏
  • 举报
回复
注意时间转换
loworth 2008-02-12
  • 打赏
  • 举报
回复
amount_in数据类型是什么

第二条:select sum(amount_in) from stocks_inout_jz where month_jz='2008年02月'
改一下再查询一下
第二条:select sum(amount_in) from stocks_inout_jz where amount_in> 0 and month_jz='2008年02月'
netcup 2008-02-12
  • 打赏
  • 举报
回复
就是啊,少了个大于0的条件
yesyesyes 2008-02-12
  • 打赏
  • 举报
回复
第一条:
where amount_in> 0 and month_jz='2008年02月'
第二条:
where month_jz='2008年02月'

条件不一样
y740504 2008-02-12
  • 打赏
  • 举报
回复
发表于:2008-02-11 07:48:341楼 得分:0
select amount_in from stocks_inout_jz where amount_in> 0


应该也没有数据,其实很简单就是没有条件满足!!!


答:是没有懑足的条件,但是为何第二条语句却出现合计数据?


发表于:2008-02-11 08:57:502楼 得分:0
amount_in 数据类型是什么?
答:amount_in是 NUMERIC(12,2)数据类型

发表于:2008-02-11 09:52:373楼 得分:0
檢查Amount_in是否有損壞的索引?

答:我没有建立Amount_In的索引呀
changjiangzhibin 2008-02-11
  • 打赏
  • 举报
回复
LZ贴下表内容,瞧瞧撒
dgdba 2008-02-11
  • 打赏
  • 举报
回复
檢查Amount_in是否有損壞的索引?
liuyann 2008-02-11
  • 打赏
  • 举报
回复
amount_in 数据类型是什么?
xingtianzhang2008 2008-02-11
  • 打赏
  • 举报
回复
select amount_in from stocks_inout_jz where amount_in> 0


应该也没有数据,其实很简单就是没有条件满足!!!


22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧