1

I have a query like this:

SELECT BookSize(page_count) as Size, count(*) as NmbrBoooks 
    FROM books 
    WHERE page_count IS NOT NULL 
        AND page_count > 0 
    GROUP BY Size;

The output is as follows:

+-----------+------------+
| Size      | NmbrBoooks |
+-----------+------------+
| ExtraLong |          3 |
| Long      |         11 |
| Medium    |         51 |
| Short     |         27 |
+-----------+------------+

I would like to sort this according to the book's length so I have the following row sequence from top to bottom: Short, Medium, Long, ExtraLong.

What is the best way to achieve this?

1 Answer 1

1

Try this:

select BookSize(page_count) as Size, count(*) as NmbrBoooks from books
where page_count is not null and page_count > 0 group by Size order by page_count;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.