Hi,
I have a table with a document's history. The table's fields are: docid (int), name (varchar), version(int), status(varchar)
status could be = under construction, published, expired
with each editing of a document, a new record is inserted and the version number is incremented. Here is an example document:
docid, name, version, status
2, 'my doc', 1, 'under construction'
2, 'my doc', 2, 'under construction'
2, 'my doc', 3, 'under construction'
2, 'my doc', 4, 'published'
here is another example:
docid, name, version, status
3, 'my doc b', 1, 'under construction'
3, 'my doc b', 2, 'under construction'
3, 'my doc b', 3, 'under construction'
3, 'my doc b', 4, 'published'
3, 'my doc b', 5, 'under construction'
here is another example:
docid, name, version, status
6, 'my doc c', 1, 'published'
I'd like to run a query that would show me a count of all documents that are 'under construction',
where
the version number is the greatest version number that is under construction
and
the greatest version under construction is greater than published (if published even exists)
so....some logic: a document does not need to have a published version; once a document is published the previous version under construction should be ignored
Any suggestions would be greatly appreciated.
I have a table with a document's history. The table's fields are: docid (int), name (varchar), version(int), status(varchar)
status could be = under construction, published, expired
with each editing of a document, a new record is inserted and the version number is incremented. Here is an example document:
docid, name, version, status
2, 'my doc', 1, 'under construction'
2, 'my doc', 2, 'under construction'
2, 'my doc', 3, 'under construction'
2, 'my doc', 4, 'published'
here is another example:
docid, name, version, status
3, 'my doc b', 1, 'under construction'
3, 'my doc b', 2, 'under construction'
3, 'my doc b', 3, 'under construction'
3, 'my doc b', 4, 'published'
3, 'my doc b', 5, 'under construction'
here is another example:
docid, name, version, status
6, 'my doc c', 1, 'published'
I'd like to run a query that would show me a count of all documents that are 'under construction',
where
the version number is the greatest version number that is under construction
and
the greatest version under construction is greater than published (if published even exists)
so....some logic: a document does not need to have a published version; once a document is published the previous version under construction should be ignored
Any suggestions would be greatly appreciated.