sql server - List users that are part of maximum concurrency session -


i have database table data shown below. trying list users members of maximum number of concurrent users condition. able maximum concurrency using solution provided itzik ben_gan simple lookup on google "calculating concurrent sessions, part 3" there. data set answer 3 (session rows ending 174,175,176) have researched web far found ways count number of concurrent sessions. want extend bit further , actual users concurrent.

i have attempted along these lines.

select l.visit_id, l.party_id, l.from_date,

(select count(*) visit2 l2 l2.party_id != l.party_id , l2.from_date <= l.from_date ) comeins,

(select count(*) visit2 l2 l2.party_id = l.party_id , l2.thru_date <= l.thru_date ) comeouts

from visit2 l

my expected result

  • party_id
  • 1000008021
  • 1000006018
  • 1000000002

below table query create table.

thank time can spend on suggestions.

<style type="text/css">    table.tableizer-table {      font-size: 12px;      border: 1px solid #ccc;      font-family: arial, helvetica, sans-serif;    }    .tableizer-table td {      padding: 4px;      margin: 3px;      border: 1px solid #ccc;    }    .tableizer-table th {      background-color: #104e8b;      color: #fff;      font-weight: bold;    }  </style>  <table class="tableizer-table">    <tr class="tableizer-firstrow">      <th>visit_id</th>      <th>party_id</th>      <th>from_date</th>      <th>thru_date</th>    </tr>    <tr>      <td>1000019158</td>      <td>1000009015</td>      <td>2014-02-18 00:57:04.837</td>      <td>2014-02-18 02:08:22.003</td>    </tr>    <tr>      <td>1000019159</td>      <td>1000006000</td>      <td>2014-02-18 08:21:04.227</td>      <td>2014-02-18 10:29:28.477</td>    </tr>    <tr>      <td>1000019160</td>      <td>1000008018</td>      <td>2014-02-18 08:49:21.937</td>      <td>2014-02-18 09:13:10.937</td>    </tr>    <tr>      <td>1000019161</td>      <td>1000006019</td>      <td>2014-02-18 09:27:43.657</td>      <td>2014-02-18 10:30:17.437</td>    </tr>    <tr>      <td>1000019162</td>      <td>1000007007</td>      <td>2014-02-18 10:13:14.520</td>      <td>2014-02-18 10:29:07.733</td>    </tr>    <tr>      <td>1000019163</td>      <td>1000008011</td>      <td>2014-02-18 11:01:14.217</td>      <td>2014-02-18 11:07:20.047</td>    </tr>    <tr>      <td>1000019164</td>      <td>1000007011</td>      <td>2014-02-18 11:05:19.570</td>      <td>2014-02-18 12:48:20.787</td>    </tr>    <tr>      <td>1000019165</td>      <td>1000008018</td>      <td>2014-02-18 11:37:52.123</td>      <td>2014-02-18 14:55:55.593</td>    </tr>    <tr>      <td>1000019166</td>      <td>null</td>      <td>2014-02-18 11:40:33.583</td>      <td>2014-02-18 11:40:33.583</td>    </tr>    <tr>      <td>1000019167</td>      <td>null</td>      <td>2014-02-18 11:40:47.573</td>      <td>2014-02-18 11:40:47.573</td>    </tr>    <tr>      <td>1000019168</td>      <td>null</td>      <td>2014-02-18 11:40:54.653</td>      <td>2014-02-18 11:40:54.653</td>    </tr>    <tr>      <td>1000019169</td>      <td>1000007030</td>      <td>2014-02-18 12:15:24.957</td>      <td>2014-02-18 14:09:14.417</td>    </tr>    <tr>      <td>1000019170</td>      <td>null</td>      <td>2014-02-18 15:32:53.630</td>      <td>2014-02-18 15:35:02.327</td>    </tr>    <tr>      <td>1000019171</td>      <td>1000008018</td>      <td>2014-02-18 15:34:05.667</td>      <td>2014-02-18 16:23:50.257</td>    </tr>    <tr>      <td>1000019172</td>      <td>1000000002</td>      <td>2014-02-18 16:31:04.303</td>      <td>2014-02-18 17:09:37.147</td>    </tr>    <tr>      <td>1000019173</td>      <td>1000006008</td>      <td>2014-02-18 16:41:35.013</td>      <td>2014-02-18 17:14:53.093</td>    </tr>    <tr>      <td>1000019174</td>      <td>1000008021</td>      <td>2014-02-18 17:40:07.073</td>      <td>2014-02-18 20:10:40.720</td>    </tr>    <tr>      <td>1000019175</td>      <td>1000006018</td>      <td>2014-02-18 18:43:06.783</td>      <td>2014-02-18 18:49:16.310</td>    </tr>    <tr>      <td>1000019176</td>      <td>1000000002</td>      <td>2014-02-18 19:57:35.370</td>      <td>2014-02-18 19:57:49.297</td>    </tr>    <tr>      <td>1000019177</td>      <td>1000008021</td>      <td>2014-02-18 20:10:43.693</td>      <td>2014-02-18 20:32:34.370</td>    </tr>    <tr>      <td>1000019178</td>      <td>1000006018</td>      <td>2014-02-18 22:26:35.477</td>      <td>2014-02-18 22:26:49.773</td>    </tr>    <tr>      <td>1000019179</td>      <td>1000000002</td>      <td>2014-02-18 22:27:37.017</td>      <td>2014-02-18 22:31:14.750</td>    </tr>    <tr>      <td>1000019180</td>      <td>1000009016</td>      <td>2014-02-18 22:40:17.093</td>      <td>2014-02-18 22:40:32.523</td>    </tr>    <tr>      <td>1000019181</td>      <td>1000008021</td>      <td>2014-02-18 23:12:04.840</td>      <td>2014-02-18 23:23:27.990</td>    </tr>    <tr>      <td>1000019182</td>      <td>1000000002</td>      <td>2014-02-18 23:20:09.737</td>      <td>2014-02-18 23:26:29.827</td>    </tr>  </table>  ​

set ansi_nulls on  go    set quoted_identifier on  go    create table [dbo].[visit2](  	[visit_id] [nvarchar](20) not null,  	[user_login_id] [nvarchar](255) null,  	[party_id] [nvarchar](20) null,  	[from_date] [datetime] null,  	[thru_date] [datetime] null  ) on [primary]    go

i took guess @ data. went ahead , cross applied users have on lapping times user. tell when , there else there @ same time. group date first know time range instead of user there @ same time. gave fiddle well. http://sqlfiddle.com/#!3/20fa29/2

    select *  visit2 src cross apply(   select user_login_id +','   visit2 ins   src.party_id = ins.party_id   , ins.from_date between src.from_date , src.thru_date   xml path('')   ) otherguests(ids) 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -