如何通过一些条件过滤器找出users_id [英] how to Find out users_id with some conditions filter

查看:72
本文介绍了如何通过一些条件过滤器找出users_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的桌子

order_id | user_id | createdAt | transaction_amount

order_id作为交易的ID,user_id作为用户,createdAt作为日期,transaction_amount是每个ID订单的交易.

order_id as the id of the transaction, user_id as the user, createdAt as the dates, and transaction_amount is the transaction of each id order.

所以在Tableau上,我想找出有2个条件的时间范围"2020-01-01"到"2020-01-31"的用户

so on tableau i want to find out users in time range '2020-01-01' until '2020-01-31' with 2 conditions

  1. 用户正在范围('2020-01-31')的最后日期之前进行交易,并且至少进行了1次以上交易
  2. 并且用户至少在日期范围内("2020-01-01"至"2020-01-31")进行了1次交易

在mysql上可以用此查询描述条件

on mysql that conditions can be described with this query

HAVING SUM(createdAt <= '2020-01-31') > 1
           AND SUM(createdAt BETWEEN '2020-01-01' AND '2020-01-31')

在桌面上我做到了

[![在此处输入图片描述] [1]] [1]

[![enter image description here][1]][1]

在第一个过滤器(createdAt)上,我确定了日期范围("2020-01-01"至"2020-01-31")在第二个过滤器上(createdAt复制),我在最后一个范围之前创建了范围(<'2020-01-31')在过滤器CNTD(user_id)上,我至少计数了1.

on first filter (createdAt) i made range of dates ('2020-01-01' until '2020-01-31') on second filter (createdAt copy) i made range before last range ( < '2020-01-31') on filter CNTD(user_id) i made count distinct at least 1.

所以它出现了2223个用户,相反,当我在mysql中检查它时,它出现了1801个用户,并且mysql总是正确的,因为我在tableau中使用了mysql和im new.那我在这里错过了什么?

so it appear 2223 users, instead when i check it in mysql, its appear 1801 user, and the mysql was always right since i used mysql and im new in tableau. so what did i missed in here?

推荐答案

编辑:举个例子

  • user1做2笔交易,分别在19年12月和20日1月
  • user2在20年1月进行1次交易
  • user3在12月19日进行了2笔交易
  • user4在2月20日进行了2笔交易
  • user5在20年1月进行2笔交易

数据快照

现在,如果您的日期范围是1月20日(例如).如果您希望用户在日期范围结束(2020年1月31日)之前进行至少两笔交易,并且其中至少一笔交易应在2020年1月进行,则user1和user5满足条件.

Now if your date range is Jan-20 (say). If you want users doing at least two transactions before end of date range (31 Jan 2020) and at least one of these should be in Jan-2020 then user1 and user5 satisfy the condition.

在这种情况下,请按照以下步骤操作

In this case proceed like this-

步骤1 创建两个日期类型参数(分别为开始和结束的 parameter 1 parameter 2 日期范围)

Step-1 Create two date type parameters (parameter 1 and parameter 2 respectively for start and end of date ranges)

第2步,创建计算字段 condition ,其计算方式为

Step-2 create a calculated field condition with calculation as

{Fixed [User]: sum(
if [Trans Date]<=[Parameter 2] then 1 else 0 end)}>=2
AND
{FIXED [User]: sum(
IF [Trans Date]<=[Parameter 2] AND 
[Trans Date] >= [Parameter 1] THEN 1 ELSE 0 END)}>=1

只要满足您的给定条件,它的评估结果就会为 TRUE .参见此屏幕截图.

this will evaluate to TRUE whenever your given condition is satisfied. See this screenshot.

不用说转换日期就是您的createdAt

Needless to say trans date is your createdAt

这篇关于如何通过一些条件过滤器找出users_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆