0

コンテンツ管理システムの IIS での ODBC ログの使用から抽出された、次の例のようなテーブルがあります。

logtime ユーザー名操作ターゲット パラメータ


2012-05-24 18:13:23.000 - GET /beta.pptx title=home
2012-05-24 18:13:14.000 - GET /index.php -
2012-05-24 18:13:09.000 domain\joeh GET /css.php -

私が調べようとしているのは、誰がどのドキュメント (PPTX や DOCX ファイルなど) をダウンロードしているのかということです。target に PPTX または DOCX ファイル名が含まれる行にはそれぞれのユーザー名がないため、ログ時間からテーブルをさかのぼってトレースし、「-」以外のユーザー名エントリを持つ次の行を見つけて、 PPTX または DOCX ファイルがリストされている行に結合します。私のテストでは、これは正確なようです。では、これを実現できるような select ステートメントを作成するにはどうすればよいでしょうか。

日付スタンプと、ユーザーごとに 1 日あたり 1 つの正確なファイル名のインスタンスのみを示す、次のようにしてうまくいったと思います。

SELECT DISTINCT
v.username
, v.logdate 
, SUBSTRING(v.target, CASE WHEN CHARINDEX('=', v.target) > 0 THEN CHARINDEX('=', v.target)+1 ELSE LEN(v.target) END, LEN(v.target)) as 'fileName'

FROM ( select (InternetLog から temp2 として temp2.​​logtime <= temp.logtime and temp2.​​username != '-' order by temp2.​​logtime desc の上位 1 つの temp2.​​username を選択)、LEFT(CONVERT(DATETIME, temp. logtime, 101), 11) AS logdate, temp.target from InternetLog as temp where (RIGHT(RTRIM(temp.target),4) = 'docx' または RIGHT(RTRIM(temp.target),4) = 'pptx' ) ) AS v WHERE v.username LIKE '%johnd%' logdate desc 順

4

2 に答える 2

0
declare @temp table (logtime smalldatetime, username varchar(10), target varchar(10))
insert into @temp(logtime, username, target)
 values('2012-05-24 14:13:23.000', 'name', 'df'),
        ('2012-05-24 16:13:23.000', '-', 'sdf'),
        ('2012-05-24 18:13:23.000', '-', 'DOCX'),
        ('2012-05-24 19:13:23.000', 'sdfsdf', 'sdf'),
        ('2012-05-24 19:15:23.000', '-', 'PPTX')

select 
    (select Top 1 temp2.username
        from @temp as temp2 
        where temp2.logtime<temp.logtime 
              and temp2.username != '-' 
        order by temp2.logtime desc) as username, 
    temp.logtime, 
    temp.target 
from @temp as temp 
where temp.target like '%DOCX%' or temp.target like '%PPTX%' 
order by temp.logtime 

結果は次のとおりです。

(5 row(s) affected)
username   logtime                 target
---------- ----------------------- ----------
name       2012-05-24 18:13:00     DOCX
sdfsdf     2012-05-24 19:15:00     PPTX

(2 row(s) affected)

EDIT外側のクエリで日付範囲をフィルタリングしたい場合(そして、あなたの時間と一致しないIDのユーザー名を取得しても、元のターゲット/時間が一致するかどうかは問題ではありません)、それを外側に追加しますどこ。ユーザー名については、さらに変更する必要があります。私はそれをテストしていませんが、おそらく次のようなものです:

select 
        (select Top 1 temp2.username
    from @temp as temp2 
    where temp2.logtime<temp.logtime 
          and temp2.username != '-' 
    order by temp2.logtime desc) as username, 
        temp.logtime, 
        temp.target 
    from @temp as temp 
    join  (select Top 1 temp2.username
            from @temp as temp2 
            where temp2.logtime<temp.logtime 
                  and temp2.username != '-' 
            order by temp2.logtime desc) as users
         on 1=1
    where (temp.target like '%DOCX%' or temp.target like '%PPTX%') 
          and users.username like '%domain\user%'
          and temp.logtime < @maxtime 
          and temp.logtime > @minTime
    order by temp.logtime 

ここで、最大時間と最小時間は、フィルター処理する日時です。

于 2012-05-24T22:53:50.033 に答える
0
DECLARE @documents TABLE (DocumentName varchar(50))
DECLARE @downloads TABLE (target varchar(50))

INSERT @documents SELECT 'test.pptx'
INSERT @documents SELECT 'test2.pptx'
INSERT @downloads SELECT '/test.pptx'


SELECT *
FROM @documents doc
  INNER JOIN @downloads dwn ON dwn.target LIKE '%' + doc.DocumentName + '%'
于 2012-05-24T22:57:41.333 に答える