sql >> Database >  >> RDS >> PostgreSQL

Running Count Total met PostgresQL

Alleen het antwoord gepost om de vraag te sluiten:

-- Set "1" for counting to be used later
WITH DATA AS (

SELECT

   orders.id, 
   orders.client_id, 
   orders.deliver_on,
   COUNT(1) -- Creates a column of "1" for counting the occurrences

   FROM orders

   GROUP BY 1

   ORDER BY deliver_on, client_id

)

SELECT

   id,
   client_id,
   deliver_on,
   SUM(COUNT) OVER (PARTITION BY client_id 
                           ORDER BY client_id, deliver_on 
                           ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) -- Counts the sequential client_ids based on the number of times they appear

 FROM DATA



  1. Hoe regeleinden in Flex te gebruiken met PHP-tekenreeks

  2. MySql:initialiseer de mySql-variabele in een query

  3. Django formulier/database fout:waarde te lang voor type karakter variërend(4)

  4. Postgresql externe toegang geen pg_hba.conf-invoer voor host