2016-06-28 10 views
0

私はSQLに慣れていません...愚かな質問があれば気にしないでください。 コードに基づいてデータを実行する最初のクエリはここでhits.transactionです。トランザクションIDはNULLではありません。複数のWHERE文を含むサブクエリ...

複数のSELECT、FROMおよびWHERE文があります。これをどのように修正するのですか?あなたは、WHERE句で複数の条件を組み合わせAND/ORキーワードを使用したい場合は

SELECT 

date,fullvisitorid AS Users, 
hits.product.v2ProductName AS Product_Name, 
(hits.product.productPrice/1000000) AS Product_Price, 
(hits.product.productQuantity) AS Product_Quantity, 
(hits.product.productrevenue/1000000) AS Product_Revenue 

FROM ([DATASET]) 

WHERE hits.transaction.transactionId IS NOT NULL 

------------------------------------------------------------------- 
SELECT 
hits.eCommerceAction.action_type AS Product_Viewed 

FROM ([DATASET]) 

WHERE hits.eCommerceAction.action_type = '2' 
+2

達成するのは正確ですか?テーブルデータと期待される出力の例を提供できますか? –

+0

最初のSELECTは5列、SECONDは1列を返します。これらの結果セットをどのように「結合する」のですか? – jarlh

+0

日付、ユーザー、Product_Name、Product_Price、Product_Quantity、Product_Revenue - これらの列はすべて1つのテーブルで使用できます。これらをまとめて1つのビジュアルに表示し、表示された総製品数を表示できますVs Total Product Revenue Vs Total Product Quantity Product_Viewedは '2'の条件で引っ張られ、残りはすべて引っ張られるべきです。hits.transaction.transactionIdがNULLでない場合....またはそうでない場合、これらの列はすべてNULL値のデータを取得します –

答えて

0

あなたは

SELECT 
date,fullvisitorid AS Users, 
hits.product.v2ProductName AS Product_Name, 
(hits.product.productPrice/1000000) AS Product_Price, 
(hits.product.productQuantity) AS Product_Quantity, 
(hits.product.productrevenue/1000000) AS Product_Revenue, 
hits.eCommerceAction.action_type AS Product_Viewed 
from ([DATASET]) 
WHERE hits.transaction.transactionId IS NOT NULL 
AND 
hits.eCommerceAction.action_type = '2' 
+0

Product_Name、Product_Price、Product_Quantity、およびProduct_Revenueの列は、条件hits.transaction.transactionIdの基礎を反映する必要があります。IS NOT NULLおよびProduct_Viewedは、hits.eCommerceAction.action_type = '2' ....の基準を反映する必要があります。異なる列の2つの条件があります。 –

0

のように、これを組み合わせることができます。

SELECT 

date,fullvisitorid AS Users, 
hits.product.v2ProductName AS Product_Name, 
(hits.product.productPrice/1000000) AS Product_Price, 
(hits.product.productQuantity) AS Product_Quantity, 
(hits.product.productrevenue/1000000) AS Product_Revenue, 
hits.eCommerceAction.action_type AS Product_Viewed 

FROM ([DATASET]) 

WHERE hits.transaction.transactionId IS NOT NULL 
AND 
hits.eCommerceAction.action_type = '2' 
+0

Product_Name、Product_Price、Product_Quantity、およびProduct_Revenueカラムは、条件hits.transaction.transactionIdに基づいている必要があります.IS NOT NULLおよびProduct_Viewedは、hits.eCommerceAction.action_type = '2'の基礎を反映する必要があります。 –

+0

'hits.transaction.transactionId IS NOT NULL'あなたが言及した列に対してのみ適用可能ですか? – MusicLovingIndianGirl

+0

Product_Name、Product_Price、Product_Quantity、およびProduct_Revenueの列は、条件hits.transaction.transactionIdの基準を反映する必要があります.IS NOT NULLおよびProduct_Viewedは、hits.eCommerceAction.action_type = '2'の基本を反映する必要があります....はい異なる列の2つの条件があります。 –

関連する問題