当第一列为NULL时,我们如何将命令引导到第二列以提取数据,第二列通过Join Command与另一个表连接。
Select
competitions.name as "Competition",
to_char(to_date(date,'DY Mon DD YYYY'),'D.MM.YYYY') as "Date Aired",
case when home_team.name Is null then to_char(to_date(date,'DY Mon DD YYYY'),'MM-DD')||' '||video_jobs.event else
to_char(to_date(date,'DY Mon DD YYYY'),'MM-DD')||' '||Away_team.name||' '||'@'||' '||home_team.name end as "Title",
min(case when new_status_id = 19 then to_char(timestamp,'DD.MM.YY') end) as "Analysis Start date",
min(case when new_status_id = 13 then to_char(timestamp,'DD.MM.YY') end) as "Analysis Complete",
min(case when new_status_id = 9 then to_char(timestamp,'DD.MM.YY') end) as "Upload complete"
from video_jobs
Join job_statuses on video_jobs.status_id = job_statuses.id
join teams as Home_team on video_jobs.home_team_id = home_team.id
join teams as Away_team on video_jobs.away_team_id = Away_team.id
Join competitions on video_jobs.competition_id = competitions.id
Join video_job_status_history on video_jobs.id = video_job_status_history.video_job_id
Where video_jobs.id = 163887 --and video_jobs.market_id=9
-- and video_jobs.status_id != 32
group by
video_jobs.id,
competitions.name,
home_team.name,
答案 0 :(得分:1)
您的问题还远未明确,但我相信您正在寻找coalesce
和Postgres支持的{{1}}功能。
答案 1 :(得分:0)
您可以使用COALESCE
:
SELECT COALESCE(t1.column1, t2.column2) AS unified_column
FROM table1 AS t1
JOIN table2 AS t2 USING (joincolumn)