I just can't logically think how to do this without doing multiple queries, which I'd like to avoid if possible. I have a mysql table set up like this.
+------+----------+--------------+--------------+
| Id | Opponent | Game Date | Playoffs |
+------+----------+--------------+--------------+
| 1 | Chicago | 2020-08-20 | First Round |
| 2 | Chicago | 2020-08-22 | First Round |
| 3 | Chicago | 2020-08-24 | First Round |
| 4 | Chicago | 2020-08-26 | First Round |
| 5 | Dallas | 2020-08-28 | Second Round |
| 6 | Dallas | 2020-08-30 | Second Round |
| 7 | Dallas | 2020-09-01 | Second Round |
+------+----------+--------------+--------------+
What I want to do is pull the results so I can display them in a table like this.
+------+-------------------+----------------+
| Game | Opponent | Date |
+-------------------------------------------+
| Playoff Round: First Round |
+-------------------------------------------+
| 1 | Chicago | 2020-08-20 |
+------+-------------------+----------------+
| 2 | Chicago | 2020-08-22 |
+------+-------------------+----------------+
| 3 | Chicago | 2020-08-24 |
+------+-------------------+----------------+
| 4 | Chicago | 2020-08-26 |
+-------------------------------------------+
| Playoff Round: Second Round |
+-------------------------------------------+
| 5 | Dallas | 2020-08-28 |
+------+-------------------+----------------+
| 6 | Dallas | 2020-08-30 |
+------+-------------------+----------------+
| 7 | Dallas | 2020-09-01 |
+------+-------------------+----------------+
I just can't quite think how to do it without running separate queries on each round. I'd rather not have to do it that way, I think it's probably unnecessary. Thanks!
I'm working on an event system and would like to know how to get the range of time available to schedule. I have the following tables
Table1 (To record the availability of creating events)
| Date | Start Time | Final Time |
| ------------- |: -------------: | ----------- |
| 2019-02-01 | 09:00:00 | 12:00:00 |
| 2019-02-01 | 13:00:00 | 17:00:00 |
and then I have Table2 to properly record the events, taking into account the availability in Table1. Table2 and Table1 have the same fields. An example of the records in Table 2 would be the following:
Table2
| Date | Start Time | Final Time |
| ------------- |: -------------: | ----------- |
| 2019-02-01 | 08:00:00 | 11:00:00 |
| 2019-02-01 | 13:00:00 | 14:30:00 |
The specific question is: What would be the SQL query to be able to determine what are the remaining time ranges, available from Table1 with respect to those that have already been taken or set out in Table2.
I'm using Laravel but I can not get the exact SQL query that works for me in this case.
I would like to get this result:
| Date | Start Time | Final Time |
| ------------- |: -------------: | ----------- |
| 2019-02-01 | 08:00:00 | 09:00:00 |
| 2019-02-01 | 11:00:00 | 12:00:00 |
| 2019-02-01 | 14:30:00 | 17:00:00 |
I hope I was clear. Thanks in advance.
I have this particular use case where I have to add a string as a particular field one time for a row in an sql result set.
E.g. :-
I have the following result set:-
| id | Name | Year |
| 1 | ABCD | 2017 |
| 2 | EFGH | 2017 |
I have two string { a , b } which I need to embed into this result set as such without affecting the base table:-
| id | Name | Year | String |
| 1 | ABCD | 2017 | a |
| 2 | EFGH | 2017 | b |
How can I do this with php? or better, with sql?
What is the best way to store shop opening and closing time in the database and also how to calculate the time in PHP?
I have come up with this table design:
+----+---------+----------+-----------+------------+
| id | shop_id | week_day | open_hour | close_hour |
+----+---------+----------+-----------+------------+
| 1 | 3 | 1 | 15:00:00 | 23:00:00 |
| 2 | 3 | 2 | 15:00:00 | 23:00:00 |
| 3 | 3 | 3 | 18:00:00 | 02:00:00 |
| 4 | 3 | 4 | 18:00:00 | 02:00:00 |
| 5 | 3 | 5 | 18:00:00 | 03:00:00 |
+----+---------+----------+-----------+------------+
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| shop_id | int(11) | NO | | NULL | |
| week_day | int(11) | NO | | NULL | |
| open_hour | time | NO | | NULL | |
| close_hour | time | NO | | NULL | |
+------------+---------+------+-----+---------+----------------+
For example, on Tuesday (week_day = 2) it open at 3PM and close at 11PM (Tuesday).
On Wednesday (`week_day = 2'), it open at 6PM and close after midnight at 2AM which would be Thursday. Should after midnight time saved in same row?
Let say customer want to place an order (shop_id = 3) at 10PM on Tuesday, they should be able to do so according to the database data. However if customer want to place an order at 1AM on Thursday but the database show that week_day = 3 it close at 02:00:00
How to write in PHP to work out if the shop open or not?
Do I need to change the the table design so it would much easier to write in PHP?
Try this
http://php.net/manual/en/book.datetime.php
with this
http://php.net/manual/en/class.dateinterval.php
You can say that if close_hour is less than open_hour for a given entry that the opening hour is in the next day.
Or you could use separate week_day columns for opening and closing time.
I have this table in PostgreSQL:
appid | appname | apptype | creationtime | createdby | display
-------+-------------------------------------+---------+--------------+-----------+---------
0 | Custom | -1 | | | t
1000 | Performance/Resource | -2 | | | t
2000 | PING | 0 | | | t
2001 | HTTP | 0 | | | t
2002 | HTTPS | 0 | | | t
2003 | FTP | 0 | | | t
2004 | LDAP | 0 | | | t
2005 | IMAP | 0 | | | t
2006 | POP | 0 | | | t
2007 | SMTP | 0 | | | t
2008 | DNS | 0 | | | t
2009 | NFS | 0 | | | t
2010 | NTP | 0 | | | t
2011 | SSH | 0 | | | t
2012 | TCP | 0 | | | t
2013 | TELNET | 0 | | | t
3000 | Generic Mail (RTT) | 3 | | | t
3001 | Apache Tomcat | 2 | | | t
3002 | JBoss | 2 | | | t
3003 | MySQL | 1 | | | t
3004 | WebSphere | 2 | | | t
4000 | Microsoft Exchange Server 2003 | 3 | | | t
4001 | Exchange Server 2007 /2010 | 3 | | | t
4003 | Microsoft SQL Server 2008 | 1 | | | t
4004 | Microsoft ISA Server 2006 | 99 | | | t
4005 | Microsoft IIS | 4 | | | t
3005 | DB2 | 1 | | | t
3006 | Apache HTTP Server | 4 | | | t
3007 | Oracle | 1 | | | t
3008 | PostgreSQL | 1 | | | t
3009 | WebLogic | 2 | | | t
3010 | Adobe ColdFusion | 2 | | | t
3011 | Sybase | 1 | | | t
4007 | Microsoft SQL Server 2005 (EXPRESS) | 1 | | | t
4008 | Microsoft Team Foundation Server | 2 | | | t
4009 | Microsoft .NET | 99 | | | t
3012 | Apache Tomcat | 2 | | | f
Apache Tomcat repeats 2 times when this table shown in an dropdown. How do I disable the last row which is 3012? I have an option to delete it but this table is used in several places so I don't want to delete it.
I think the more important question is why is it in your database twice. Depending on what you're using this query for ignoring one could be just as wrong as deleting one. Maybe it has somehting to do with that being the only entry with display f. I guess you could just do WHERE display != 'f'
Tomcat appears twice because it's in the table twice, once with ID 3001 and again with ID 3012. I'd call that a problem with the data, not with the query. Does it really need to be there twice? You say you're reluctant to delete one of them because it's used in several places, but if you don't fix it now, it'll only be harder to fix later.
I'd focus on merging those duplicate rows. Find all the records (in other tables) that refer to one of this pair, and update them to refer to the other one instead. Then you can delete the one that nothing refers to anymore.
Why not use the display column? Sounds like it is for filtering out things that are not supposed to be shown. So, you could do a query like this:
SELECT appid, appname
FROM stat_applications
WHERE appid <> 0
AND appid <> 1000
AND display = 't'
If you don't want to use display, then you could just add 3012 to your list of things to ignore:
SELECT appid, appname
FROM stat_applications
WHERE appid <> 0
AND appid <> 1000
AND appid <> 3012
Or, since your exclusion list is getting longer, use NOT IN:
SELECT appid, appname
FROM stat_applications
WHERE appid NOT IN (0, 1000, 3012)