Closed. This question needs details or clarity . It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post .
Closed 22 hours ago.
Improve this question
The following table is given:
FQDN | content | Syncdate |
---|---|---|
FQDN1 | content1 | 2023-01-01 |
FQDN1 | content1 | 2023-01-02 |
FQDN1 | content2 | 2023-01-03 |
FQDN1 | content2 | 2023-01-04 |
FQDN1 | content1 | 2023-01-05 |
FQDN2 | content3 | 2023-01-01 |
FQDN2 | content3 | 2023-01-02 |
FQDN2 | content4 | 2023-01-03 |
FQDN2 | content4 | 2023-01-04 |
FQDN2 | content3 | 2023-01-05 |
As an output of my SQL-query I need the FQDN, the content and the date ONLY when the combination of FQDN and the content changes.
E.g.:
- FQDN1;content1,2023-01-01
- FQDN1;content2,2023-01-03
- FQDN1;content1,2023-01-05
- FQDN2;content3,2023-01-01
- FQDN2;content4,2023-01-03
- FQDN2;content3,2023-01-05
How can I achieve this in SQL Server?
I tried:
with cte as (
SELECT
ROW_NUMBER() OVER(PARTITION BY FQDN, content
ORDER BY FQDN, content, Syncdate DESC) AS "RowNumber",
FQDN, content, Syncdate
FROM tbl
)
select * from cte where RowNumber = '1'
But with this, I get only "2023-01-05" for FQDN1 in combination with content1.
1条答案
按热度按时间avkwfej41#
You can try