我有以下查詢,它給出MAX(date_announced)的最新date_announced,但沒有給出相應的值爲software_product_build? 如何獲取MAX的相應software_product_build值(date_announced)?如何獲得MAX函數的相應列值?
select
software_product_build,
MAX(date_announced) as date_announced
from software_product_builds
group by software_product_id
一種情況: -
select software_product_build,
MAX(date_announced) as date_announced
from software_product_builds
where software_product_build LIKE '%QCA6290.LA.0.1%' group by software_product_id;
OUTPUT:-
|------software_product_build------|-------date_announced------|
--QCA6290.LA.0.1-00001-STD.INT-6---|------2017-03-13 21:13:32---
select software_product_build from software_product_builds where date_announced='2017-03-13 21:13:32';
OUTPUT:-
CI_QCA6290.LA.0.1-03091-STD.INT-61
Classic [「組的前n」](https://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row -per-group-in-sql /) – shmosel
@shmosel - 所以我應該說除了software_product_id之外還有'by software_productbuild'組? –
你想要什麼,最大日期爲software_product_id或software_productbuild? – Rams