Skip to content

Commit

Permalink
Merge pull request #74 from thread/docs-useful-snippets
Browse files Browse the repository at this point in the history
Create useful-snippets.md with some useful DB queries
  • Loading branch information
aaron7 committed Oct 10, 2018
2 parents 2174347 + 0673467 commit 5c5d057
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/useful-snippets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Useful snippets

## Database queries

### Query current states for all labels
```
SELECT history.label_name, history.created, history.new_state
FROM history
JOIN (
SELECT label_name, MAX(created) AS max_created
FROM history
GROUP BY label_name
) latest_states
ON
history.created = latest_states.max_created AND
history.label_name = latest_states.label_name;
```

### Count number of labels in a specific state

```
SELECT COUNT(*)
FROM history
JOIN (
SELECT label_name, MAX(created) AS max_created
FROM history
GROUP BY label_name
) latest_states
ON
history.created = latest_states.max_created AND
history.label_name = latest_states.label_name
WHERE history.new_state = 'STATE_NAME';
```

0 comments on commit 5c5d057

Please sign in to comment.