sql - How to merge a select statement with a new dynamic values as columns? -
in sql server code, have select statement
select distinct a.hirelastname, a.hirefirstname, a.hireid, a.position_id, a.barnumber, a.archived, a.datearchived, b.position_name newhire join position b on a.position_id = b.position_id join workperiod c on a.hireid = c.hireid a.archived = 0 , c.inquiryid not null order a.hireid desc, a.hirelastname, a.hirefirstname
and want add new column it. column not column table, used store float
calculation make existing columns.
the number calculated this: @acc
a.hireid
above select statement.
cast((select count(*) hire_response hireid = @acc , (hireresponse = 0 or hireresponse = 1)) float) / cast((select count(*) hire_response hireid = @acc) float)
how can this? thanks.
this should it
select distinct a.hirelastname, a.hirefirstname, a.hireid, a.position_id, a.barnumber, a.archived, a.datearchived, b.position_name, cast((select count(*) hire_response hireid = a.hireid , (hireresponse = 0 or hireresponse = 1)) float) / cast((select case when count(*) = 0 1 else count(*) end hire_response hireid = a.hireid) float) myspecialcolumn newhire join position b on a.position_id = b.position_id join workperiod c on a.hireid = c.hireid a.archived = 0 , c.inquiryid not null order a.hireid desc, a.hirelastname, a.hirefirstname
Comments
Post a Comment