зеркало из
				https://github.com/iharh/notes.git
				synced 2025-11-04 15:46:08 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			42 строки
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			42 строки
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
partition
 | 
						|
    https://edu.postgrespro.ru/sqlprimer/sqlprimer-2019-msu-04.pdf
 | 
						|
    ! p68
 | 
						|
    select
 | 
						|
        ...
 | 
						|
        count(*) over (
 | 
						|
            partition by date_trunc('month', b.book_date)
 | 
						|
            order by b.book_date
 | 
						|
        ) as count
 | 
						|
    from
 | 
						|
        ...
 | 
						|
        join bookings b on ...
 | 
						|
    ;
 | 
						|
    over - necessary keyword (count function became a window-one)
 | 
						|
    ! p76
 | 
						|
        first_value
 | 
						|
        ??? WINDOW - to name over-conditions (https://habr.com/ru/post/268983/)
 | 
						|
 | 
						|
row_number
 | 
						|
rank
 | 
						|
lag
 | 
						|
lead
 | 
						|
first_value, last_value, nth_value
 | 
						|
- aggregates like sum, count
 | 
						|
 | 
						|
sample
 | 
						|
    select depname, empno, salary, avg(salary) over (partition by depname) from empsalary;
 | 
						|
 | 
						|
      depname  | empno | salary |          avg
 | 
						|
    -----------+-------+--------+-----------------------
 | 
						|
     develop   |    11 |   5200 | 5020.0000000000000000
 | 
						|
     develop   |     7 |   4200 | 5020.0000000000000000
 | 
						|
     develop   |     9 |   4500 | 5020.0000000000000000
 | 
						|
     develop   |     8 |   6000 | 5020.0000000000000000
 | 
						|
     develop   |    10 |   5200 | 5020.0000000000000000
 | 
						|
     personnel |     5 |   3500 | 3700.0000000000000000
 | 
						|
     personnel |     2 |   3900 | 3700.0000000000000000
 | 
						|
     sales     |     3 |   4800 | 4866.6666666666666667
 | 
						|
     sales     |     1 |   5000 | 4866.6666666666666667
 | 
						|
     sales     |     4 |   4800 | 4866.6666666666666667
 | 
						|
    (10 rows)
 |