Tableau中的sql操作

本文介绍了如何在Tableau中使用SQL操作,包括case when进行条件判断,not like排除特定字符串,distinct进行去重,以及where子句筛选特定时间段的数据。通过示例展示了SQL语句在Tableau中对应的计算字段创建方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tableau中的sql操作

1.case when

当paytype为10时按照括号中字段出现顺序做空判断,不为空则finishdate取该字段的值

  • sql:

case when paytype='10' then coalesce(log_finish_time,finishDate,amount_platform_pay_time)  

else coalesce(log_finish_time,finishDate)

end

as finishDate

 

  • Tableau:

创建计算字段

IF paytype=10 and not ISNULL(log_finish_time) then [log_finish_time]
ELSEIF paytype=10 and not ISNULL(finishdate) then [finishdate]
ELSEIF paytype=10 and not ISNULL(amount_platform_pay_time ) then [amount_platform_pay_time]  
ELSEIF not ISNULL(log_finish_time) then [log_finish_time]      
ELSEIF not ISNULL(finishdate) then [finishdate]
end

2. not like

ownername的值不包含‘测试’

  • sql:

ownername not like '%测试%'

  • Tableau:

创建计算字段

not CONTAINS('测试',[ownername])

like同理

3.distinct

左连接后产生许多重复的cardnum,对其进行去重并对money求和

  • sql:

distinct cardnum

sum(money)

  • Tableau:

ZN(SUM({FIXED [cardnum] : MIN([money])}))

因为重复的cardnum元组money值是相等的,取重复元组的最小值,不影响去重结果

4.where

只取上个月的数据进行计数

  • sql

count(truckbrokerordercode)

where DATEDIFF(day,orderdate,GETDATE())>=30 and DATEDIFF(day,orderdate,GETDATE())<=60

  • Tableau:

COUNTD(IF DATEDIFF('day',[orderdate],DATETRUNC('day',NOW()))>=30 and DATEDIFF('day',[orderdate],DATETRUNC('day',NOW()))<=60 
then [truckbrokerordercode] END)

选取距今日30天至60天的数据统计订单数量

 

sql语句均是提取主要语句,不完整

持续更新......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值