根据值的数量进行不同的排序
我
选择了标题、成本、订单日期 来自客户 C、书籍 B、订单 其中 C.lastname='LUCAS' AND C.firstname='JAKE' 按 ORDERDATE 订购,成本 DESC
但如果只有 1 件商品,则必须按 ORDERDATE 订购,否则订单成本 DESC
需要进行哪些更改?
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 order cost DESc
what changes does it need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只有一件商品,因此只有一个 orderdate,那么您不需要对该结果进行排序,因为只有 1 行,它已经按照您想要的任何顺序排序。因此,您可以使用
它将始终按成本排序。这适用于多个项目,也适用于单个项目,因为按成本排序对于一行并不重要。
也许这个查询还有更多内容?
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
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?