Jump to content

Recommended Posts

My delimma...

I have a field in my database that contains eye information as it pertains to being blind or not. The records can have values like so:

 

CF - Counting Fingers

NIL - Totally blind

etc stored as the acronym only

 

or the field can have a visual acuity like such

20/200

or 20/20

etc...

 

I want two sql statements

one to be able to pull up the records on people who have any letter acronym or greater than or equal to a 20/200 visual acuity

and another to pull up the records of people who have less than a 20/200 visual acuity

 

Would it be better to search them all and filter them with a php function or is there a way I can do this with a SQL statement?

Well, my first suggestion would be house the data in two seperate fields.

 

I'd have the acryonym set as an ENUM field, and the other set as a varchar.

 

Having said that, given your problem...there is a way around it :)  If your acronyms are typically 3 characters, you could use some of MySQL's string functions.

 

Ex:

 

SELECT * from blind_ass_patients_table where LENGTH(howBlind) > 3 ORDER BY howBlind ASC

 

This way your return result from MySQL isn't going to be as large, and it does some initial sorting for you. 

 

Not a perfect solution, but might work :)

Well, my first suggestion would be house the data in two seperate fields.

I'd have the acryonym set as an ENUM field, and the other set as a varchar.

Having said that, given your problem...there is a way around it  If your acronyms are typically 3 characters, you could use some of MySQL's string functions.

No, you are better creating a relational table i.e

 

people

=====

id

name

eyeSightScoreId

 

eyeSightScore

=============

eyeSightScoreId

title

 

So in the eyeSightScore table I have the following records

 

1 20/20

2 20/200

3 Counting Fingers

4 Totally Blind

 

In the people table I have the following records

 

1 Joe Bloggs 3

2 John Doe 4

3 Sue Smith 4

4 Paul Smith 2

 

The tables are related on the field eyeSightScoreId

 

So If I want to find all people who are totally blind I run the following query

 

SELECT name FROM people WHERE eyeSightScoreId=4

 

If I want people who are less than 20/20 vision I can run the follwing query

SELECT name FROM people HAVING eyeSightScoreId IN(2,3,4)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.