【问题标题】:Translate the SQL statement in to Qlikview expression将 SQL 语句转换为 Qlikview 表达式
【发布时间】:2014-08-14 05:53:06
【问题描述】:

目前我正在尝试编写一个表达式,但我只知道如何在 SQl 语句中查询它

SQL:

select * from Orders o
where o.product_name != MBProductName 
AND
o.transaction_id in 
(
select m.transaction_id from marketBasket m where m.product_name = MBProductName);

我想把结果做成表格形式的图表。

当我选择 MBProductName 时,它​​会执行此查询。

谁能帮我翻译一下?提前致谢

我的脚本:

LOAD  
 Customer_ID, 
 Customer_Country, 
 Customer_Gender, 
 Customer_BirthDate, 
 Customer_Age_Group, 
 Customer_Type, 
 Customer_Age, 
 Real_age, 
 Continent, 
 Country_Name


Orders:
LOAD  
 Customer_ID, 
 Employee_ID, 
 Street_ID, 
 Order_Date, 
 Delivery_Date, 
 Order_ID As %%MarketBasket, 
 Order_ID,
 Order_Type, 
 Product_ID, 
 Quantity, 
 Total_Retail_Price, 
 CostPrice_Per_Unit, 
 Discount, 
 Profit_per_Product, 
 PrfitRange, 
 ProfitMarginRange


Products:
LOAD Product_ID, 
 Product_Line, 
 Product_Category, 
 Product_Group, 
 Product_Name, 
 Supplier_Country, 
 Supplier_Name

TmpMarketBasket:
Load
%%MarketBasket AS TmpOrderId,
Product_ID AS TmpProductId,
Order_Date As TmpOrderDate
Resident Orders;

LEFT JOIN
Load 
Product_ID AS TmpProdcutId,
Product_Name AS TmpProductName,
Product_Line AS TmpProductLine,
Product_Category As TmpProductCategory,
Product_Group As TmpProductGroup
Resident Products;

MarketBasket:
LOAD
TmpOrderId                 as %%MarketBasket,
TmpProductName            as MBProductName,
TmpProductGroup             as MBProductGroup
RESIDENT TmpMarketBasket;

DROP TABLE TmpMarketBasket;

【问题讨论】:

    标签: sql expression qlikview


    【解决方案1】:

    我不确定MarketBasket 表是如何填充的(也许您可以提供其中一些数据的示例),但是,您可以使用必填字段创建一个直表,然后使用以下表达式作为数量总计:

    =sum({$<Product_Name-={$(=GetFieldSelections(MBProductName))}>} Quantity)
    

    这样做的目的是获取您在MBProductName 上所做的选择,然后在对Quantity 字段求和期间将其从Product_Name 中的值中排除。由于 Product_Name = MBProductName 的总和为零,这些条目将从表中删除。

    【讨论】:

    • 感谢您的回复,MarketBasket 表有 3 列:%%MarketBasket(order_ID),MBProductName(ProductName),MBProductGroup(Product_Group)
    猜你喜欢
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多