将SQL语句转换为Qlikview表达式

时间:2014-08-14 05:53:07

标签: sql expression qlikview

目前我正在尝试编写表达式,但我只知道如何在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;

1 个答案:

答案 0 :(得分:1)

我不确定如何填充MarketBasket表(也许您可以提供一些来自它的数据的示例),但是,您可以创建一个包含所需字段的直表,然后使用以下表达式数量总计:

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

这样做是为了对MBProductName进行的选择,然后在Product_Name字段求和期间将其从Quantity中的值中排除。作为Product_Name = MBProductName总和为零的条目,这些将从表中得到抑制。