Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mick79's avatar

Help with a query..... please

I'm struggling with what seems to be a more complicated query than I thought.

I have a client who requires a dashboard showing a bunch of his company's main KPIs. all of this is fine except one.

Sample data set... hmm how do you add images in here?

alt text

The rule

Give me a number of all the meals that were "available" for at least 90 minutes.

what this means in SQL: count all rows where "meal_id" = X AND "availability" = 1 AND there is NOT a row with "availability" = 2 created within 90 mins of it.

Basically, on the site when someone adds an item for sale it goes in the database as availability = 1 and if they take it off it gets recorded as availability = 2

So I need to see all the things that have been for sale for at least 90 mins.

Clear as mud?

0 likes
3 replies
Mick79's avatar

The example above would NOT qualify as it was removed only 8 minutes after it was put up.

jlrdw's avatar

Well you have to query between two times constantly, or have a button to click to just do it manually. I don't think anyone is going to constantly stir at the screen, probably too busy with other things.

There are may examples of querying between times.

and if they take it off it gets recorded as availability = 2

Could make it 0, then a checkbox could be used.

1 like
Mick79's avatar

I've decided I implemented this very poorly. I'm currently rewriting it. I feel like this forced me to think about the problem in a lot more depth and I've come up with a much more clever way to handle the whole onsale / offsale process.

Quietly frustrated that the people who ask for this stuff actually have no idea how much thought and problem solving is involved... however, that's probably for another type of forum to rant about.

Please or to participate in this conversation.