Max_Leb

Untitled

Jan 9th, 2023
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.06 KB | None | 0 0
  1. SELECT * FROM statuses s ;
  2.  
  3. SELECT * FROM incident_table it ORDER BY "timestamp" ;
  4.  
  5. SELECT ts.DATE,
  6. (
  7.     SELECT COUNT(*)
  8.     FROM incident_table it
  9.     INNER JOIN statuses s ON s.id = it.status_type
  10.     WHERE s.label = 'new' AND it.id = (
  11.         SELECT sit.id
  12.         FROM incident_table_table AS sit
  13.         WHERE sit.task_id = it.task_id AND DATE(sit.TIMESTAMP) <= ts.DATE
  14.         ORDER BY sit.TIMESTAMP DESC, sit.id DESC LIMIT 1
  15.         )
  16. ) AS number_of_new,
  17.  
  18. (
  19.     SELECT COUNT(*)
  20.     FROM incident_table it
  21.     INNER JOIN statuses s ON s.id = it.status_type
  22.     WHERE s.label = 'completed' AND it.id = (
  23.         SELECT sit.id
  24.         FROM incident_table_table AS sit
  25.         WHERE sit.task_id = it.task_id AND DATE(sit.TIMESTAMP) <= ts.DATE
  26.         ORDER BY sit.TIMESTAMP DESC, sit.id DESC LIMIT 1
  27.         )
  28. ) AS number_of_completed
  29. FROM (
  30.     SELECT DISTINCT DATE("timestamp") AS DATE
  31.     FROM incident_table
  32.     WHERE DATE("timestamp") > DATE((SELECT MAX("timestamp") FROM incident_table), '-30 day')
  33.     ORDER BY DATE ASC
  34. ) AS ts;
  35.  
Advertisement
Add Comment
Please, Sign In to add comment