Skip to content
Advertisement

How to achieve partition by kind of functionality using variables in MySQL 5.7

I’m using an old version of MySQL. I cannot upgrade it due to some strong reasons. I’ve a table PatientAppointment with only 2 columns. Here is the table:

I want 5 things:

  1. Create a new column in runtime monthOfCheckup from dateOfCheckup
  2. Convert duration into integer field as minutes
  3. Accumulating total for each month (not date)

I was able to achieve these 3 points with this query:

Here is the fiddle for the same.

Now the remaining 2 points are:

  1. BillElig1 This can be boolean or text, doesn’t matters. I just have to put ‘Y’ if the total for that particular month is >=20
  2. BillElig2 This can be boolean or text, doesn’t matters. I just have to put ‘Y’ if the total for that particular month is >=40

For these 2 points you can see this fiddle.

Please help me.

Advertisement

Answer

And again use UDV.

fiddle

I use 1 and 0 instead of Y and NULL.

Of course, the columns order in output list and ordering are critical again.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement