Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm having trouble getting my head around exactly what is the best way to build an application which is supposed to manage a nursery, particularly, who is in what room when.
Nurseries have several rooms and each room has an age range allowed in it, and a maximum number of children it can accommodate at any one time.
Children get booked in in a rota type style for mornings and afternoons, so a kid might be booked to be in on the following times.
monday am pm
tuesday pm
wed pm
thurs am pm
fri am pm
sat
sun
So I collect this rota in a table like so:
id
child_id
mon_am <-- if booked in then 1, if not then 0
mon_pm
tues_am
etc...
And then allocate a child to a room.
Now when adding a new child I need to be able to check to see what rooms there are spaces available in, so that I can know whether the appropriate room has the spare capacity. So with the info above and assuming the room in question has a capacity (for example) of 1 child, if someone wants to sign up for that room on tues and wed am, then they can because the first kid isn't booked in at that time.
I'm a bit new to all this and I'm having trouble figuring out what I need to do to check if a room has spare capacity. Can anyone help me out at all?
thanks
SELECT COUNT(1) AS `numChildrenBooked` FROM `your_table` WHERE `mon_am` = 1;
will return the number of rows in which mon_am is == 1 in your table. Compare that to the maximum number of children per room to check if there's space available.
What's bad in your db-structure probably is (I think) that you can only plan for one week at once...
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have got the mysql table which includes data about users who visited my web service (IP address, date). The one IP address can be logged in my database only once per day.
What is the best way to create the table contains visits from last month? I want something like:
30.10.2016 | 1457
31.10.2016 | 1604
01.11.2016 | 1590
etc
Sorry for English and maybe the very simple question, first time on stack :)
use this sql code to create a table for last month visitor count.
CREATE TABLE last_mon_visit AS
SELECT DISTINCT date, COUNT(ip_address)
FROM visit
WHERE YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
GROUP BY date
i would suggest to create view instead of table.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Let me start by saying that I am super new to web development so I apologize if this is a stupid question, but I have been looking around for days and haven't been able to find anything.
I am re-working the website for my wedding photography studio with a bunch of photographers in different locations and with slightly different skill sets and prices. I am currently using HTML, CSS, PHP, and mySQLi to build the site.
We are about to start expanding aggressively, so I would like to have our website do some of our work for us before the client ever contacts us. The general idea is that I want clients to be able to come to our site and search through our photographers based on location, skills, price and availability before they contact us to set up a meeting and book their photographer. So, I am setting it up so our photographers can make a profile, upload some general info and portfolio examples etc. into a mySQLi database. Then, clients can quickly search to find the right photographer for their wedding. That part was easy enough. Create a table, each photographer gets a row with individual columns for each piece of profile info.
Where I got stuck is the photographers' schedules. Clients start searching for photographers as much as 2 YEARS in advance and we want to make sure that client searches only bring up photographers who are actually available for their wedding date.
I have been looking around in here for days and from what I have read, trying to save multiple pieces of data in one column (which is to say, all of the individual dates that a particular photographer already booked) is a big no-no because then you can't query the data, which I obviously need to be able to do here. But, I seriously doubt that adding 730 columns (corresponding to one column per day for the next 2 years) to my user table is the solution, especially if we expand to hundreds (maybe even thousands?) of photographers over time.
Can anyone point me in the right direction here?
Thanks in advance!
You're thinking about the problem in the wrong way, what you want to know is if the photographer is booked, not if they are free.
You will probably have one table with all your photographer info, then have another table with bookings.
For example:
photogID | StartDate | EndDate
--------------------------------------------
1 | 9.16.2015 9:00 | 9.16.2015 17:00
2 | 9.17.2015 9:00 | 9.17.2015 17:00
2 | 9.18.2015 7:00 | 9.20.2015 15:00
1 | 10.18.2015 7:00 | 10.18.2015 11:00
1 | 10.19.2015 15:00 | 10.21.2015 19:00
When you query, you will search for the set of all photographers, except the ones who already have a booking that day.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i am working on php mysql HR application and i have a table with some field like date and salary and incremented salary as shown the below screenshot.
i want a list of a record of each year but some year(date) not in a data base how to get that year as shown in 2nd screenshot
Thanks..
You don't want that result.
In the first place, ID = 2 is already in use for the year 2014; assigning 2013 to it is a bad, bad idea. In the second place, it makes no sense to say that the salary for 2013 is 3500, and the increment is 0, when 2013 isn;'t in the database.
If 2013 is supposed to have those values, then put them in the database.
Otherwise, create a table of years (or a table of integers), and include it in your query with an outer join.
create table years (
yr integer primary key
);
insert into years values
(2012), (2013), (2014), (2015), (2016),
(2017), (2018), (2019), (2020), (2021);
Now you can join those two tables with an outer join. The coalesce() expression isn't strictly necessary with an outer join, but I think it expresses the result you want.
select salaries.id, coalesce(salaries.date, years.yr) as date,
salaries.salary, salaries.increment
from years
left join salaries on
salaries.date = years.yr
where years.yr between 2012 and 2015
order by years.yr;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm building a browser game which you can shoot missiles on factories.
This is example of a similar SQL table:
user_ID iron steel metal gold
1 21 30 39 25
2 7 10 25 50
I need each missile to destroy 1 factory.
For example I shoot 10 missile, so 10 factories are destroyed. But I need it to have completely randomly and even.
The problem is if according to this SQL table, if I shoot for example 40 missile on user_ID '2'.
In best case I destroy 10 factories of each kind. But how can I do it when I don't know if there is enough of each kind?
First, divide the number of missiles by the number of factory types that have at least 1 factory. If all the types have at least this many factories, subtract this from each column.
If any of the types have less than this, they'll be totally wiped out. Reduce them to 0 and subtract their original totals from the number of missiles. Then start again, using just the remaining missiles.
Repeat this until you use up all the missiles or all factories are wiped out.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I've done a system for a client where they can nominate colleagues for doing a great job. Each person has 12 nominations to give annually.
So I've got a database with a table nominations which stores, id, nominator(id), nominated(id), reason and date.
I've also got a table user which stores user data such as, total nominations given, received, id, email etc.
So I'm creating a page from which you can pull reports.
Here you can choose a start date and end date and amount of records you would like.
How would the SQL query look to determine who made the most nominations between the specified dates?
I'm not a SQL guru at all...so any help would be appreciated very much.
After some research I've managed to find out COUNT(*) is the way to go...but don't want to run a query for every user that nominated between the specified dates...and sorting it this way could be a problem.
Please any help would be great.
select nominator, count(*)
from yourTable
where nominatedDate >= '1 Jan 2013' and nominatedDate <= '31 Jan 2013'
group by nominator
When you do aggregation functions (like COUNT. MIN, MAX, AVG) you either need to apply them to every row selected, which will give just one row in the output, or to GROUP BY items you want to make into sub-totals. In this case, for each value of Nominator in the table we get the Nominator value, and the count of rows containing that value.
The Where clause limits the counted rows to those where nominatedDate is in the given range. You can put AND and OR other tests (its already got one and).