dongxie7683 2017-12-22 21:59
浏览 264
已采纳

如何在SQL中将值显示为Y或N?

I am creating a database for a small clinic in central America. The database has a "visit" table with dozens of fields for a series of yes or no questions.

I know that the best (simplest, most efficient) way to store binary values in SQL is using the bit datatype (x), however I know I could also use datatypes of char(1) for "Y" or "N" at the tradeoff of using more space (x).

Originally, I had planned on using the bit datatype and storing 1 for yes and 0 for no, however I don't know how to make this display as Y or N in php.

Currently, in a separate table, I have values for HIV and Diabetes stored as 0 or 1 and I perform an inner join in my SQL select statement to two separate tables relating 1 to Y and 0 to N.

If I were to continue with this technique then I would need to make dozens of tables relating 1 to Y and 0 to N. This seems inefficient and very redundant.

Is there a way to relate multiple columns of a table to one table relating 1 to Y and 0 to N? I'm using PHPmyadmin.

  • 写回答

2条回答 默认 最新

  • douyinjiao9351 2017-12-22 22:28
    关注

    With respect, you don't need to scramble to save table space for a small clinic. Write your program in the way that's easiest to maintain.

    The savings you'll achieve by using bits instead of simpler column types amount, probably, to tens of thousands of bytes. (=nothing measurable).

    If you use any flavor of int (tinyint?) you can translate to text in your query.

     SELECT IF(column=1,'Sí','No') column
    

    for example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致