【发布时间】:2012-06-06 11:40:19
【问题描述】:
我有这张桌子:
table session(
ID number,
SessionID VarChar,
Date,
Filter
)
此表包含搜索信息,如下所示:
ID SessionID Date filter
4 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=5
6 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon
7 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon&meagPixel=12.1
8 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon
10 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Nikon
12 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=12.1
13 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=12.1&opticalZoom=True
14 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 meagPixel=12.1&opticalZoom=True&brand=Panasonic
16 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=500.00
18 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=499.00
19 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=499.00&brand=Olympus
21 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000
22 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica
23 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica&price=1995.00
24 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True
25 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2
26 peqq421gaspts3nuulq5mwcq 24/05/2012 13:50 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2&weight=345
27 peqq421gaspts3nuulq5mwcq 24/05/2012 13:58 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2
41 poiq41111spts00000q5aaaa 27/05/2012 13:48 meagPixel=5
我想获得独特的搜索。唯一搜索是:
- 用户(会话)的最长搜索(过滤)
- 如果第一个过滤器发生变化 - 需要将其视为新搜索(过滤器)
由于 ASP.NET 不保证 SessionID 是唯一的(SessionID,Date)是唯一的。
我没走多远:
SELECT MAX(Filter)
FROM Session
GROUP BY SessionID
顺便说一句,我给出的示例表数据的结果应该返回:
ID SessionID Date filter
4 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 meagPixel=5
7 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Canon&meagPixel=12.1
10 peqq421gaspts3nuulq5mwcq 24/05/2012 13:48 brand=Nikon
14 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 meagPixel=12.1&opticalZoom=True&brand=Panasonic
16 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=500.00
19 peqq421gaspts3nuulq5mwcq 24/05/2012 13:49 price=499.00&brand=Olympus
26 peqq421gaspts3nuulq5mwcq 24/05/2012 13:50 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2&weight=345
41 poiq41111spts00000q5aaaa 27/05/2012 13:48 meagPixel=5
感谢您的帮助和指导。
【问题讨论】:
-
您能否再次检查您的预期输出。 brand=Canon 和 brand=Canon&meagPixel=12.1 具有相同的第一个过滤器,但它们分别列出。虽然 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel=16.2&weight=345 只有一个条目,而在主表中之后你有一个记录 zoomRange=2000&brand=Leica&price=1995.00&opticalZoom=True&meagPixel =16.2
-
因为不是很清楚所以改了。
-
非常抱歉我现在只编辑我的帖子 - 我使用 sql server compact 4 而不是 sql server 标准版
标签: sql sql-server-ce sql-server-ce-4