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语句均是提取主要语句,不完整
持续更新......