Jump to content

Some Help With A Query


murfitUK

Recommended Posts

I've inherited a mysql database and will eventually get around to sorting it out to a better format. I've got to do a couple of queries quickly but am struggling! Any help appreciated.The first table is called `addresses` and has two fields `id` and `description`. Simple enough: 1=Room 1, 2=Room2 etc.The second table is called `details` and has a field called `id` (just a normal auto-increment index), `room` into which is inserted the `addresses`.`id` number from the first table. There are two fields called `from` and `to` which hold dates in the format "2008-11-24" and a field called `status` which holds a value of "let" or "void". (There are other fields for the name of a tenant and the daily rent charge.)If, say, Mr Smith was there from 1st August 2008 to 20th Jan 2009, the fields would be:`id`=34 (or whatever)`room`=7 (taken from the other table)status`="let"`from`="2008-08-01"`to`=`2009-01-20"etcThere should be another line created when the property becomes void:`id`=35 (or whatever)`room`=7 (taken from other table)`status`="void"`from`="2009-01-21"`to`=NULL (I assume because the propery is still void)etc The NULL will then be updated if the property is let again.If a tenant is currently in residence:`id`=36 (or whatever)`room`=9 (taken from other table)`status`="let"`from`="2008-12-18"`to`=NULLOne of the reports I need to do now is to generate a list of properties that are void. I can easily select where `status`="void" and `to`=NULL but sometimes the table is not updated properly and they forget to create a "void" record after updating the "let" record with an end date. How do I do this? I only need the select the `room` field from the `details` table - I'll do the join to get the address later.(If I was starting from scratch I wouldn't set it up this way but for now need to work with what I've got.)

Link to comment
Share on other sites

  • 2 weeks later...
.....One of the reports I need to do now is to generate a list of properties that are void. I can easily select where `status`="void" and `to`=NULL but sometimes the table is not updated properly and they forget to create a "void" record after updating the "let" record with an end date. How do I do this? I only need the select the `room` field from the `details` table - I'll do the join to get the address later.(If I was starting from scratch I wouldn't set it up this way but for now need to work with what I've got.)
i haven't anylized properly the issue (actualy too long and life too short) but when you write "..table is not updated properly" may be something is wrong at that point. Why shoudn't a table be updated properly, I can't help but think the program that manage that table doesn't work fine, or may be you need to add some trigger in mysql side.regardsstefano de boni
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...