sqlserver 經典sql語句case

2021-08-14 17:16:48 字數 1810 閱讀 2374

select  (alipay_order_num + succ_refund_order_num)  ,case  (alipay_order_num+succ_refund_order_num) when 0 then 1 else  (alipay_order_num+succ_refund_order_num) end   from ysf_shoptrade nolock

select 

case succ_refund_order_num when 0 then 1 else succ_refund_order_num end as num ,

case  (alipay_order_num+succ_refund_order_num) when 0 then 1 else  (alipay_order_num+succ_refund_order_num)  end as two   ,

case succ_refund_order_num when 0 then 1 else succ_refund_order_num end /case  (alipay_order_num+succ_refund_order_num) when 0 then 1 else  (alipay_order_num+succ_refund_order_num)   end from  ysf_shoptrade

select  case when (alipay_order_num+succ_refund_order_num)=0 then 0 else (alipay_order_num+succ_refund_order_num)   end  from ysf_shoptrade

select  a.seller_id ,

a.thedate ,

succ_trade_amt as '已收貨金額' ,

succ_trade_num as '交易成功筆數 ' ,

succ_auction_num as '已收貨商品數' ,

succ_refund_trade_amt as '退款成功金額' ,

case when (alipay_order_num+succ_refund_order_num)=0 then 0

else convert(decimal(18, 4), convert(decimal(18, 4), succ_refund_order_num/ convert(decimal(18, 4), (alipay_order_num+succ_refund_order_num)))) end  as '七天完結率'

from    [dbo].[ysf_shoptrade] a

select 

seller_id,

thedate,

convert(decimal(18,4), succ_trade_amt)  as '已收貨金額' ,

succ_trade_num as '交易成功筆數 ' ,

succ_auction_num as '已收貨商品數' ,

succ_refund_trade_amt as '退款成功金額' ,

1-(case when (alipay_order_num+succ_refund_order_num)=0 then 0 else convert(decimal(18,4),convert(decimal(18,4), succ_refund_order_num/convert(decimal(18,4),(alipay_order_num+succ_refund_order_num))))    end) '七天完結率' from ysf_shoptrade  where seller_id='601879343' and thedate between 20151222  and 20151227

mysql和sqlserver的sql語句區別

mysql 檢視系統內所有資料庫 show databases 查詢資料庫內所有表 show tables 顯示表結構 desc 表名 sqlserver 檢視系統內所有資料庫 select name,database id,create date from sys.databases 查詢資料庫內...

MySQL和Sql Server的sql語句區別

1 自增長列的插入 sqlserver中可以不為自動增長列插入值,mysql中需要為自動增長列插入值。2 獲取當前時間函式 sqlserver寫法 getdate mysql寫法 now 3 從資料庫定位到表。sqlserver寫法 庫名.dbo.表名 或者 庫名.表名 注 中間使用兩個點 sele...

MySQL和Sql Server的sql語句區別

1 自增長列的插入 sqlserver中可以不為自動增長列插入值,mysql中需要為自動增長列插入值。2 獲取當前時間函式 sqlserver寫法 getdate mysql寫法 now 3 從資料庫定位到表。sqlserver寫法 庫名.dbo.表名 或者 庫名 表名 注 中間使用兩個點 sele...