1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
create database sandbox;
go
use sandbox;
go
create table testgroup
(
colonne1 int,
colonne2 int,
date1 date
);
go
insert into testgroup (colonne1, colonne2, date1) values (1, 1, '01/01/2017'), (1, 1, '01/01/2017'), (1, 1, '01/02/2017'), (1, 1, '05/01/2017'), (1, 2, '01/05/2017'), (1, 2, '01/05/2016'), (2, 2, '01/05/2017'), (2, 2, '05/05/2017'), (2, 2, '01/02/2017'), (2, 2, '18/05/2017');
select *, count(distinct date1), min(date1), max(date1)
from testgroup
where year(date1) = 2017
group by colonne1, colonne2; |
Partager