帮看一个SQL查询结果 - MS-SQL Server / 基础类
/*
表里3条记录片段:
SORDER EDA BUN CUST NOUBA JITU0 APRICE
RR128254 0 1 CSZ003U CSZ004U 62.700 62.10000000
RR128254 0 2 CSZ003U CSZ004U 213.750 62.10000000
RR128254 0 3 CSZ003U CSZ004U 8.550 62.10000000
*/
select case when cust='chf001j'and nouba='chf001j' then ceiling(jitu0*aprice)
when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then round(jitu0*aprice,0)
else round(jitu0*aprice,2) end
from xract where sorder='RR128254'
--照理应出来 round(jitu0*aprice,2)的结果,但是却出来ceiling(jitu0*aprice)的结果,怎么回事?
有点蹊跷,不知道啥原因。我在我机器上没问题,出来正确结果而来。
为了正确说明你得到的结果,将then 后都用字符串试试比如 then 'a' then 'b' else 'c'
你可以这样测试,就知道它读取的是哪个值
select case when cust='chf001j'and nouba='chf001j' then 'a' when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then 'b'
else 'c' end
from xract where sorder='RR128254'
出来应该是c
to 2楼,我试过了,用字符串得到的结果是对的,但一用正式的语句就不行了。见鬼。
select
case when cust='chf001j'and nouba='chf001j' then 'a'
when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then 'b'
else 'c' end,
* from xract where sorder='RR128254'
出来是c
但用
select case when cust='chf001j'and
相关问答:
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
将一个查询语句赋给一个变量,如下:
DECLARE @STR NVARCHAR(MAX)
SET @STR='SELECT * from SALE_PROD'
怎么样才能执行它呢?
请高手,仁兄,侠姐帮帮忙啊
多谢,可以啦,高手啊
直接执行就行了
exec ......
select o_customer,o_price from orders having o_price >=avg(o_price)
select o_customer,o_price from orders where o_price >=(select avg(o_price) from orders)
我感觉没有区别啊,怎么在mysql会有 ......