sort differently depending on # of values
I have
select title, COST, ORDERDATE from customers C, books B, orders where C.lastname='LUCAS' AND C.firstname='JAKE' order by ORDERDATE, cost DESC
but it has to be order by ORDERDATE if 1 item only, else or开发者_开发百科der cost DESc
what changes does it need?
If you only have one item and therefore only one orderdate then you don't need to order that result since there is only 1 row, it is already sorted in any order you want. Thus you can just use
ORDER BY cost DESC
It will always be sorted by cost. This works for mutliple items and also a single item because ordering by cost doesn't matter for one row.
Perhaps though there is more to this query?
精彩评论