Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

mysql - SQL How to replace values of select return?

In my database (MySQL) table, has a column with 1 and 0 for represent true and false respectively.

But in SELECT, I need it replace for true or false for printing in a GridView.

How to I make my SELECT query to do this?

In my current table:

 id   |  name    |  hide
  1   |  Paul    |  1
  2   |  John    |  0
  3   |  Jessica |  1

I need it show thereby:

  id  |  name    |  hide
  1   |  Paul    |  true
  2   |  John    |  false
  3   |  Jessica |  true
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have a number of choices:

  1. Join with a domain table with TRUE, FALSE Boolean value.
  2. Use (as pointed in this answer)

    SELECT CASE WHEN hide = 0 THEN FALSE ELSE TRUE END FROM
    

    Or if Boolean is not supported:

    SELECT CASE WHEN hide = 0 THEN 'false' ELSE 'true' END FROM
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...