我有這個表:複雜SQL編寫
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
BTW的結果,因爲我給了應該返回這個示例表數據:
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
感謝您的幫助和指導。
你能再次檢查你的預期輸出嗎? *品牌=佳能*和*品牌=佳能和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 * –
因爲它不是很清楚我會改變它。 – Nir
我非常非常抱歉,我現在只編輯我的帖子 - 我使用sql server compact 4而不是sql server standard edition – Nir