【发布时间】:2017-11-10 18:45:33
【问题描述】:
EDIT:因为我使用的是 ExactTarget (Salesforce Marketing Cloud),所以我只能访问 SELECT 语句。没有任何好的 SQL 可以使这变得简单。
我有一张客户表和一张优惠券表。我想为符合条件的客户分配唯一代码,但我有点卡在查询 #1 上。 (查询 #2 是一个简单的连接。)
表 1
+-------------+-------------+------------+ |客户 |优惠券类型 |优惠码 | +-------------+-------------+------------+ |客户1 | 20pctoff | | |客户2 | 20pctoff | | |客户3 | 10pctoff | | |客户4 |空 | | +-------------+-------------+------------+表 2
+-------------+-------------+------------+ |优惠券类型 |优惠码 |分配给 | +-------------+-------------+------------+ | 10pctoff |优惠券1 | | | 20pctoff |优惠券2 | | | 30pctoff |优惠券3 | | +-------------+-------------+------------+查询 #1 将导致以下结果:
客户1 = 优惠券2
Customer2 = none(没有更多 20pctoff 可用)
客户 3 = 优惠券 1
Customer4 = none(不符合条件)
更新表 2 的第二个 SQL 是一个简单的连接(我不需要帮助)。
【问题讨论】:
-
Customer2 = none (没有更多 20pctoff 可用) 优惠券数量存储在哪里?还是每种类型只有一种??
-
Customer2 = none -- 因为给我代码的人没有给我足够的代码。我有一个单独的例程来订购更多优惠券。 Customer2 稍后会得到他们的。
-
我觉得我将不得不使用 2 个临时表... SELECT row_number() as id, customer, coupontype where coupontype = 20pctoff // 选择 row_number() 作为 id, couponcode , coupontype where coupontype = 20pctoff // select t1.customer, t1.coupontype, t2.couponcode from table1 t1 left join on table2 t2 on t1.id = t2.id
-
如果您有两张 20pctoff 优惠券,表 2 中的第四个条目是什么??
-
这将是另一个优惠券类型/优惠券代码对。 (可能是“20pctoff”/“Coupon4”)。抱歉,我的 table2 示例应该更好。
标签: sql