phrankbooth
Posting Yak Master
162 Posts |
Posted - 2013-11-18 : 21:57:47
|
In the table below how can I return the rows where [Date] < than the MIN JoinedDate in each grouping of the JoinedTag field??Declare @tmp table ([Date] Date, Tag varchar(10), Product Varchar(10), ProdType varchar(10), JoinedDate Date, JoinedTag varchar(10))insert into @tmp values ('2013-10-31', 'Tag1', 'Prod1', 'Type1', Null, NULL), ('2013-10-31', 'Tag1', 'Prod1', 'Type1', Null, NULL), ('2013-10-31', 'Tag1', 'Prod1', 'Type1', Null, NULL), ('2013-11-01', 'Tag1', 'Prod1', 'Type1', Null, NULL), ('2013-11-01', 'Tag1', 'Prod1', 'Type1', Null, NULL), ('2013-11-01', 'Tag1', 'Prod1', 'Type1', Null, NULL), ('2013-11-02', 'Tag1', 'Prod1', 'Type1', '2013-11-02', 'Tag1'), --for this joinedtag return all rows less than the joineddate ('2013-10-31', 'Tag2', 'Prod2', 'Type2', Null, NULL), ('2013-10-31', 'Tag2', 'Prod2', 'Type2', Null, NULL), ('2013-10-31', 'Tag2', 'Prod2', 'Type2', Null, NULL), ('2013-11-01', 'Tag2', 'Prod2', 'Type2', '2013-11-01', 'Tag2'), --for this joinedtag return all rows less than the joineddate ('2013-11-02', 'Tag2', 'Prod2', 'Type2', Null, NULL), ('2013-11-02', 'Tag2', 'Prod2', 'Type2', Null, NULL), ('2013-11-02', 'Tag2', 'Prod2', 'Type2', Null, NULL)So for Tag1, the reult should be: ('2013-10-31', 'Tag1', 'Prod1', 'Type1', Null, NULL) ('2013-10-31', 'Tag1', 'Prod1', 'Type1', Null, NULL) ('2013-10-31', 'Tag1', 'Prod1', 'Type1', Null, NULL) ('2013-11-01', 'Tag1', 'Prod1', 'Type1', Null, NULL) ('2013-11-01', 'Tag1', 'Prod1', 'Type1', Null, NULL) ('2013-11-01', 'Tag1', 'Prod1', 'Type1', Null, NULL)And for Tag2, the result should be: ('2013-10-31', 'Tag2', 'Prod2', 'Type2', Null, NULL) ('2013-10-31', 'Tag2', 'Prod2', 'Type2', Null, NULL) ('2013-10-31', 'Tag2', 'Prod2', 'Type2', Null, NULL)Thanks--PhB |
|