pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: winston cheung <winston_cheung@163.com>
To: pgsql-admin@postgresql.org
Subject: windown function count Unexpected results
Date: Fri, 5 May 2017 11:31:21 +0800
Message-ID: <eaec97a5-9412-7edc-15ff-c5c193649c75@163.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>

hello

When I used the count in the window function, I found that the results 
were not true. In the table I use department_id as a partition 
condition, I think when department_id = 30, the calculation of salary 
<3000 should be 4, when department_id = 50,the calculation of salary < 
3000 should be 20, why the value of each line are different?

Thanks a lot!

postgres@160.40:5410/testdb=# select department_id as dep_id, 
concat(first_name, ' ', last_name) as employee_name, salary, count(*) 
over w from employees where salary<3000 window w as (partition by 
department_id order by salary desc);
  dep_id |   employee_name   | salary  | count
--------+-------------------+---------+-------
      30 | Shelli Baida      | 2900.00 |     1
      30 | Sigal Tobias      | 2800.00 |     2
      30 | Guy Himuro        | 2600.00 |     3
      30 | Karen Colmenares  | 2500.00 |     4
      50 | Michael Rogers    | 2900.00 |     2
      50 | Timothy Gates     | 2900.00 |     2
      50 | Vance Jones       | 2800.00 |     5
      50 | Mozhe Atkinson    | 2800.00 |     5
      50 | Girard Geoni      | 2800.00 |     5
      50 | John Seo          | 2700.00 |     7
      50 | Irene Mikkilineni | 2700.00 |     7
      50 | Douglas Grant     | 2600.00 |    10
      50 | Randall Matos     | 2600.00 |    10
      50 | Donald OConnell   | 2600.00 |    10
      50 | Joshua Patel      | 2500.00 |    15
      50 | Peter Vargas      | 2500.00 |    15
      50 | Martha Sullivan   | 2500.00 |    15
      50 | James Marlow      | 2500.00 |    15
      50 | Randall Perkins   | 2500.00 |    15
      50 | James Landry      | 2400.00 |    17
      50 | Ki Gee            | 2400.00 |    17
      50 | Hazel Philtanker  | 2200.00 |    19
      50 | Steven Markle     | 2200.00 |    19
      50 | TJ Olson          | 2100.00 |    20
(24 rows)


winston , regards




-- 
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin



view thread (5+ messages)  latest in thread

Message-ID: <eaec97a5-9412-7edc-15ff-c5c193649c75@163.com>
Permalink:  ../eaec97a5-9412-7edc-15ff-c5c193649c75@163.com/
Also on:    postgresql.org/message-id/eaec97a5-9412-7edc-15ff-c5c193649c75@163.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: winston_cheung@163.com
  Subject: Re: windown function count Unexpected results
  In-Reply-To: <eaec97a5-9412-7edc-15ff-c5c193649c75@163.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox