[英]How can I select all the rows which do not share a column value with another row which is null?
[英]How can I query unique columns, conditionally choosing which row based on another column's value?
我有以下設置:
date | event | hits
Jan | A | 0
Jan | B | 2
Jan | C | 0
Feb | A | 4
Feb | B | 0
Feb | C | 0
我正在尋找返回的查詢:
我希望對上表的查詢返回:
Feb | A | 4
Jan | B | 2
Feb | C | 0
SELECT
(select edate from stuff sx where s.event=sx.`Event` ORDER BY sx.hits DESC,sx.edate DESC limit 1) date,
s.event, (select hits from stuff sx where s.event=sx.`Event` ORDER BY sx.hits DESC,sx.edate DESC limit 1) hits
FROM stuff s
GROUP BY Event
order by event
表填充日期字段定義為日期。 對於大表不是很有效,但是可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.