简体   繁体   中英

How assing new column value for only specific one

I have a bit complex query to do in BigQuery.

Please find below example.

I have:

Team Team type
Team 1 B1
Team 1 B2
Team 2 B3
Team 2 B4
Team 3 B5
Team 3 B6

I need to have

Team Teamtype Team_model
Team 1 B1 Team x
Team 1 B2 Team 1
Team 2 B3 Team 2
Team 2 B4 Team 2
Team 3 B5 Team 3
Team 3 B6 Team 3

In similar logic like this

CASE WHEN teamtype = A1 THEN "Team x" ELSE team_model = %team% END AS team_model

I know that in biq query you cant do this way. Would anyone know please how to perform this type of action?

Thank you!

Regards, Martin

You were on the right track. You may use this version:

SELECT Team, Teamtype, CASE Teamtype WHEN 'B1' THEN 'Team x' ELSE Team END AS Team_model
FROM yourTable
ORDER BY Team, Teamtype;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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