2015-07-09 121 views
1

我有一個有關訪問IP地址和國家/地區網站信息的多維數據集。每個國家/地區計算不同的IP地址

我想檢索每個國家/地區的唯一IP地址數,如下表所示。

+-------------+----------+ 
| country  | count IP | 
+-------------+----------+ 
| germany  | 2  | 
| netherlands | 3  | 
+-------------+----------+ 

但所有我想出到目前爲止是這樣的:

+-------------+---------------+--------+ 
| country  | IP   | visits | 
+-------------+---------------+--------+ 
| germany  | 65.49.14.152 | 5  | 
|    | 66.55.144.187 | 12  | 
| netherlands | 93.114.46.11 | 2  | 
|    | 93.115.94.85 | 5  | 
|    | 141.105.1.7 | 1  | 
+-------------+---------------+--------+ 

這是由該查詢產生:

SELECT 
    NON EMPTY 
    {Hierarchize({[Measures].[Visits]})} ON COLUMNS 
,NON EMPTY 
    CrossJoin 
    (
     [Geografy.Localizacion].[Country].MEMBERS 
    ,[RemoteClient].[IP].MEMBERS 
    ) ON ROWS 
FROM [VisitsCube]; 

如何修改這個查詢產生的結果在第一個tabel?

回答

0

創建一個計算的成員,它將保存每個唯一IP的計數。並從行軸移除[RemoteClient].[IP].Members

WITH MEMBER Measures.[Count IP] AS 
SUM(Distinct(EXISTING [RemoteClient].[IP].Members), [Measures].[Visits]) 

SELECT NON EMPTY [Geografy.Localizacion].[Country].Members ON 1, 
NON EMPTY Measures.[Count IP] ON 0 
FROM [VisitsCube] 
+0

這個工作,如果我刪除'存在'。如果不是:語法錯誤(在Pentaho Saiku上)。 – mgr326639

0

AdvWrks我測試了這種方法:

WITH 
    MEMBER [Measures].[CountX] AS 
    Sum 
    (
     [Customer].[Customer Geography].[City] 
    ,IIF 
     (
     NOT isempty([Measures].[Internet Sales Amount]) 
     ,1 
     ,null 
    ) 
    ) 
SELECT 
    {[Measures].[CountX]} ON 0 
,NON EMPTY 
     [Product].[Product Categories].[Category] 
ON 1 
FROM [Adventure Works] 
WHERE 
    [Geography].[Geography].[Country].&[Canada]; 

它給那裏有互聯網銷售Amoutn每個產品類別城市數量的計數:

enter image description here

適用於您的情況我認爲它是這樣的:

WITH 
    MEMBER [Measures].[CountX] AS 
    Sum 
    (
     [RemoteClient].[IP].MEMBERS 
    ,IIF 
     (
     NOT isempty([Measures].[Visits]) 
     ,1 
     ,null 
    ) 
    ) 
SELECT 
    NON EMPTY 
    [Geografy.Localizacion].[Country].MEMBERS ON 1 
,NON EMPTY 
    [Measures].[CountX] ON 0 
FROM [VisitsCube]; 
+0

這也工作。謝謝。 – mgr326639

+0

這應該更快。 – whytheq

相關問題