-1

I've been writing a query in big query cause I'm still learning, so I use the sandbox to write my sentences, but I don't get success, I try so many times in so many ways but I don't. Is there some special condition to the 'IF' function that works?

SELECT stn,date,

FROM `bigquery-public-data.noaa_gsod.gsod2020`

IF(temp=9999,9, NULL, temp) AS temperature,

I tring to solve it a one week later, and already try do mane times in so many ways to arrive in one result that not return erro in the Big Query, I hope that someone analysing and gimme one answer to it! Thank you!

  • You should post the actual error message in full, then include the important phrase from the error in the title for the question. "Any Problems" is _very_ open ended, we prefer more focused questions on this site. This helps other users to find solutions to their problems, the first thing you would do before posting here is to search for the error message, so lets help the community to find your question and to learn from the solution. – Chris Schaller Nov 28 '22 at 23:33

1 Answers1

0

The IF function should be used in the SELECT part, example :

WITH Numbers AS (
  SELECT 10 as A, 20 as B UNION ALL
  SELECT 50, 30 UNION ALL
  SELECT 60, 60
)
SELECT
  A,
  B,
  IF(A < B, 'true', 'false') AS result
FROM Numbers

+------------------+
| A  | B  | result |
+------------------+
| 10 | 20 | true   |
| 50 | 30 | false  |
| 60 | 60 | false  |
+------------------+

In your code snippet the IF is placed the FROM without WHERE condition, it can't work like that.

Mazlum Tosun
  • 5,761
  • 1
  • 9
  • 23