Bonjour,

Je possède une table qui me donne les statistiques d'ouvertures d'e-mails envoyés à mes clients

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CREATE TABLE [STAT_EMAIL]
	([lv_email] [varchar] (255),
	[ReportId] [int],
	[type] [varchar] (10) ,
	[time] [smalldatetime])
GO
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7090632, 'Send', '2010-10-27 11:53:14'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7090632, 'Open', '2010-10-27 12:26:27'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7091760, 'Send', '2010-11-09 12:24:15'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7091760, 'Open', '2010-11-09 17:29:07'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7091760, 'Open', '2010-11-09 17:29:12'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7092523, 'Send', '2010-11-17 14:12:24'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7093070, 'Send', '2010-11-23 15:08:34'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7093452, 'Send', '2010-11-26 17:23:53'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7093970, 'Send', '2010-12-02 16:40:49'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094065, 'Send', '2010-12-03 14:31:03'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094065, 'Open', '2010-12-03 18:57:43'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094264, 'Send', '2010-12-06 16:48:31'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094264, 'Open', '2010-12-06 17:35:59'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094800, 'Send', '2010-12-10 17:12:56'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094800, 'Open', '2010-12-11 19:14:51'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094800, 'Open', '2010-12-13 08:14:14'
INSERT STAT_EMAIL SELECT 'toto@hotmail.com', 7094800, 'Click', '2010-12-13 08:14:28'
...
Je souhaite connaître pour chaque e-mail de ma table donné le jour où il est le plus susceptible d'ouvrir son e-mail : [type] = 'Open'. J'ai bien compris qu'avec mon DATEPART(dw, [time]) j'obtenais le jour en question, j'ai un premier élément de réflexion avec :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
SELECT	EMAIL, DATEPART(dw, [TIME]) AS SEG_JOUR, COUNT(*) AS NB
FROM	STAT_EMAIL (NOLOCK)
WHERE	[TYPE] = 'Open'
GROUP	BY EMAIL, DATEPART(dw, [TIME])
Mais ensuite, comment extraire pour chaque e-mail le jour où NB est le max ?

PS : Je suis actuellement sous SQL Server 2000