sql - Grouping using analytic functions -


i have table below. group id , if count(item) >1 , if there duplicate items, take distinct first , apply following condition.
1) if count(item) > 1 then, filter data equal 65 or 66. 2) if count(item) = 1, nothing.

+----+------+ | id | item | +----+------+ |  1 |  65  | +----+------+ |  1 |  66  | +----+------+ |  1 |  01  | +----+------+ |  2 |  93  | +----+------+ |  3 |  11  | +----+------+ |  3 |  12  | +----+------+ |  4 |  23  | +----+------+ |  4 |  23  | +----+------+ 

output:

+----+------+ | id | item | +----+------+ |  1 |  65  | +----+------+ |  1 |  66  | +----+------+ |  2 |  93  | +----+------+ |  4 |  23  | +----+------+ 

so far tried this.

select id, item (select table.*, count(1) on (partition id) cnt       table      ) tablt cnt > 1 , item in (65, 66) or cnt = 1; 

please try using following code:

with t1  (select id, item, count(1) on (partition id) cnt       tablet      )  select id, item t1      cnt > 1  ,      item in (65, 66) or      cnt = 1 ; 

requirement not clear me, sure "with" clause resolve purpose.

  • abhi

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -