SQL - Ugly combination of GROUP BY and COALESCE

后端 未结 5 1780
Happy的楠姐
Happy的楠姐 2021-01-18 08:01

I have a table with data similar to the following:

[ID], [State], [foo], [DateCreated], [DateUpdated]

The longer I work on this, the uglier my SQL is getti

5条回答
  •  温柔的废话
    2021-01-18 08:25

    Try this:

    select state_name,foo,max(dateUpdated) from state where state_name in (select state_name from state group by state_name having count(distinct foo)=1) group by state_name,foo;
    

提交回复
热议问题