【发布时间】:2015-09-23 18:48:24
【问题描述】:
我有如下数据
ID Name Description DataSource Year
1 Apple Sweet & Tasty Source_A 2016
1 Apple Red and Sweet & Tasty Source_B 2015
2 Apple Delicious Source_A 2016
2 Apple Delicious and Red Source_C 2015
3 Apple Source_C 2013
3 Apple Green and Large Source_B 2016
就我而言,我想优先考虑 source_B,因为它更可靠。因此,如果有来自 Soure_B 的数据,我想为特定 ID 显示该行并忽略其他 ID。如果来自 source_B 的数据不存在,那么我只想显示来自其他来源的数据。另外,我想只显示一行最近的数据。
在上面的例子中,结果应该是这样的
ID Name Description DataSource Year
1 Apple Red and Sweet & Tasty Source_B 2015
2 Apple Delicious Source_A 2016
3 Apple Green and Large Source_B 2016
【问题讨论】:
-
这里是similar question,但使用的是 [mysql]。
标签: sql-server select sql-order-by