Quantcast
Channel: group – 100% Private Proxies – Fast, Anonymous, Quality, Unlimited USA Private Proxy!
Viewing all articles
Browse latest Browse all 24

Group by bit column

$
0
0

I want Group by rows with active column like result

I tray with this code and I Do not get result

    WITH CTE as (   SELECT     RN = ROW_NUMBER() OVER (ORDER BY id),     *   FROM test ) SELECT   convert(nvarchar(50),[Current Row].datetime,120) + ' To ' +  convert(nvarchar(50),[Next Row].datetime,120)  FROM CTE [Current Row] LEFT JOIN CTE [Previous Row] ON   [Previous Row].RN = [Current Row].RN - 1  and (ISNULL( [Previous Row].active,0)=0) and [Current Row].active=1 RIGHT JOIN CTE [Next Row] ON   [Next Row].RN = [Current Row].RN + 1  and [Current Row].active=1 and isnull([Next Row].active,0)=0 
id date active
1 2021-08-08 12:05:17.817 1
2 2021-08-08 12:05:20.817 1
3 2021-08-08 12:05:23.817 1
4 2021-08-08 12:05:26.817 1
5 2021-08-08 12:05:29.817 1
6 2021-08-08 12:05:32.817 1
7 2021-08-08 12:05:35.817 1
8 2021-08-08 12:05:38.817 1
9 2021-08-08 12:05:41.817 0
10 2021-08-08 12:05:44.817 0
11 2021-08-08 12:05:47.817 1
12 2021-08-08 12:05:50.817 1
13 2021-08-08 12:05:53.817 0
14 2021-08-08 12:05:56.817 0
15 2021-08-08 12:05:59.817 1
16 2021-08-08 12:06:02.817 0
17 2021-08-08 12:06:05.817 1
18 2021-08-08 12:06:08.817 1
19 2021-08-08 12:06:11.817 1
20 2021-08-08 12:06:14.817 0
21 2021-08-08 12:06:17.817 1
22 2021-08-08 12:06:20.817 1

and get rusult like this

date duration count
2021-08-08 12:05:17.817 To 2021-08-08 12:05:38.817 00:00:24 8
2021-08-08 12:05:47.817 To 2021-08-08 12:05:50.817 00:00:06 2
2021-08-08 12:05:56.817 To 2021-08-08 12:05:59.817 00:00:03 1
2021-08-08 12:06:05.817 To 2021-08-08 12:06:11.817 00:00:09 3
2021-08-08 12:06:17.817 To 2021-08-08 12:06:20.817 00:00:06 2

i want group by with active and date like top result

The post Group by bit column appeared first on 100% Private Proxies - Fast, Anonymous, Quality, Unlimited USA Private Proxy!.


Viewing all articles
Browse latest Browse all 24

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>