Seth Pritchard Seth Pritchard - 5 months ago 10
SQL Question

Im trying to return a string based on a value from a list

So I have a list of ID's that later put a string to describe the issue.

I want to filter these out by their id and display a string based on the primary id#

select
sol.solution `Solution`,
count(sol.id) `Solution Count`,
case sol.id when 8,9,10,11,12,13,14,15,16,25,29,33,37,40,41,42,48,51 then 'Hardware'
else 'Software' end `HW/SW`
from tickets t
join ticket_solutions tsol
on tsol.ticket_id =t.id
join solutions sol
on tsol.solution_id = sol.id

Answer

Since your description is not 100% clear here is just my guess:

SELECT
sol.solution `Solution`,
COUNT(t.id) `Solution Count`,
IF(sol.id IN (8,9,10,11,12,13,14,15,16,25,29,33,37,40,41,42,48,51),'Hardware','Software') `HW_SW`
FROM tickets t
JOIN ticket_solutions tsol
  ON tsol.ticket_id =t.id
JOIN solutions sol
  ON tsol.solution_id = sol.id
GROUP BY sol.id