I want to return it as true or false after it is summarized in Group By.

Asked 2 years ago, Updated 2 years ago, 45 views

samples table

 id, A, B
1,  1, 1
2,  1, 2
3,  1, 3
4,  1, 3
5,  2, 1

For tables like the ones above,

I would like to write SQL that returns true if B contains 2, or false if not.

Response Example

A,contains
1, true
2, false

How can I write SQL that satisfies the above?

mysql sql

2022-09-30 18:19

1 Answers

(From comments)

How to determine if a valueappears in a GROUP BY group may be helpful.

SELECTA, IF(SUM(B=2), 'true', 'false') AS contents FROM samples GROUP BY;


2022-09-30 18:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.