简体   繁体   English

查询如何根据单一条件选择数据

[英]Query on how to select data based on single condition

Need your help to review the below request. 需要您的帮助以查看以下请求。

i am using the below query and what i want to achieve is as below 我正在使用以下查询,我想要实现的如下

i am trying to extract the min value of the new_status_id and not fetch any other details of any other status at all. 我正在尝试提取new_status_id的最小值,并且根本不获取任何其他状态的任何其他详细信息。 Basically i am getting more than one line as output for one v_id that i input where as the desired output is one line and min(timestamp) to get fetched under column name Upload as defined below 基本上,对于一个我输入的v_id,我得到的输出多于一行,其中所需的输出是一行和min(timestamp)要以列名Upload提取,定义如下

Select
to_char(to_date(date,'DY Mon DD YYYY'),'MM-DD')||' '||Away_team.name||' '||'@'||' '||home_team.name as "Title",
video_jobs.id as "Job Id",
markets.name as "Market",
round as "Round",
to_char(to_date(date,'DY Mon DD YYYY'),'DD-Mon-YY') as "Date Aired",
competitions.name as "Competition",
Home_team.name as "Home Team",
Away_team.name as "Away Team",
job_statuses.name as "Job Status",
networks.name as "Network",
stadiums.name as "Stadium",
Round(images_count/3600.0,2) as "Footage Hours",
round(sum(minutes_in_logo_finder)/60.0,2) as "Logo Picker Time",
Round(sum(minutes_in_hits_editor)/60.0,2) as "Hits Editing Time",
Round(sum(minutes_in_branding)/60.0,2) as "Branding Time",
Round(sum(minutes_in_tagging)/60.0,2) as "Tagging Time",
Round(sum(minutes_in_qc)/60.0,2)as "QC Time",
Round(sum(minutes_in_idle)/60.0,2) as "Idle Time",
Round(sum(loading_time)/60.0,2) as "Loading Time",
Round(sum(minutes_in_logo_finder+minutes_in_hits_editor + minutes_in_branding +minutes_in_tagging +minutes_in_qc+minutes_in_idle+loading_time)/60.0,2) as "Total"

from video_jobs 
Join markets on video_jobs.market_id = markets.id
Join stadiums on video_jobs.stadium_id = Stadiums.id
Join job_statuses on video_jobs.status_id = job_statuses.id
Join competitions on video_jobs.competition_id = competitions.id
Join networks on video_jobs.network_id = networks.id
Join sessions on video_jobs.id = sessions.job_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 video_job_status_history on video_jobs.id = video_job_status_history.video_job_id

Where video_jobs.id > 163026  

group by
video_jobs.id,
markets.name,
video_jobs.round,
stadiums.name,
job_statuses.name,
competitions.name,
networks.name,
video_jobs.images_count,
home_team.name,
Away_team.name,
video_jobs.date

order by 
video_jobs.id

Add the condition into the where clause: 将条件添加到where子句中:

select min(timestamp) as "Uplaod"
from v_jobs
where v_id = 1234 and new_status_id = 25;

EDIT: 编辑:

In that case, what you want is conditional aggregation: 在这种情况下,您需要的是条件聚合:

select min(case when new_status_id = 25 then timestamp end) as MinTimestamp25
. . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM