Home > Back-end >  get wrong answer from sql
get wrong answer from sql

Time:12-20

first `

Select Count(*) From Covids Where AsiDurumu=1

I get 12 from first query

Second

Select MAX(covidId) From Covids 

I get 18 from second query

Third Query

Select CAST(Count(*) AS FLOAT) / MAX(CovidId) as Asi_Olanlarin_Covid_Orani From Covids Where AsiDurumu=1

when i wrote this query i got 0.705858.. but i must get 0.66. why i didn't get

CodePudding user response:

Use a case expression to do conditional aggregation:

Select sum(case when AsiDurumu = 1 then 1.0 else 0.0 end ) / MAX(CovidId) as Asi_Olanlarin_Covid_Orani
From Covids
  •  Tags:  
  • sql
  • Related