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!
Related
I am working on a project for recharge and bill payments. I am confused about whether to use a single table for all type of recharges like mobile recharge, dtn recharge, electricity bill, water bill, card recharges, etc, which is difficult or do I create separate tables for each type of recharge and work on them.
Table has colums
recharge_id PRIMARY KEY,
recharge_amount ,
recharge_status,
recharge_time,
user_id,
payment_id
The data has to be added into the table when there is any recharge process with status and other details.
Although, you didn't show anything you tried, i think this is a viable question.
A possible approach would be to create one table for your type and one for your recharges
Something like the following should work
create a table recharge_type like
+----+------------------+--------+
| id | name | active |
+----+------------------+--------+
| 1 | Mobile recharge | 1 |
| 2 | Dtn recharge | 1 |
| 3 | electricity bill | 1 |
| 4 | water bill | 1 |
| 5 | card recharge | 1 |
+----+------------------+--------+
and your table recharge
+----+------------------+---------+------------+--------+--------+------------+
| id | recharge_type_id | user_id | payment_id | amount | status | time |
+----+------------------+---------+------------+--------+--------+------------+
| 1 | 1 | 1 | 1 | 2.00 | 1 | 2019-03-05 |
| 2 | 2 | 1 | 2 | 3.00 | 3 | 2019-03-05 |
| 3 | 2 | 1 | 2 | 4.00 | 4 | 2019-03-05 |
+----+------------------+---------+------------+--------+--------+------------+
With this type of construction you are pretty flexible for nearly any approach.
If you want to understand why this is a good approach, you should read
some articles about first normal form. You can find an article
here on Wikipedia.
I have a search page that allow user to key in the member ID and it will list out all the downline that belongs to the user.
I am using easyui treegrid to generate the downline.
Now i need to do an extra button to export out all the downline that belongs to the search id and export each line of information into excel file.
This is part of my data, and actually the real data had more column and about 4000++ of data.
Is there anyone can help me or some references? Please let me know if you need more info
+-------------+---------------+---------------------------+------------+
| MemberID | parent_id | Name | Age |
+-------------+---------------+---------------------------+------------+
| 1 | 0 | Cassy | 8 |
| 2 | 1 | Peter | 7 |
| 3 | 1 | Maide | 7 |
| 4 | 1 | Samda | 7 |
| 5 | 4 | Kinso | 7 |
| 6 | 4 | March | 7 |
| 7 | 2 | Sandy | 10 |
| 8 | 0 | Mandy | 12 |
+-------+---------------+----------------------------------------------+
Giving you an example of problem I am facing creating mysql query. using group_concat or group by is not giving me the result I want.
Can anyone please tell me how can i achieve following results? If it can be solved using procedure or views, it is ok.
user
===============
| Id | UserId |
=====+========|
| 1 | 297 |
---------------
workex
=======================================================
| wid | UserId | title | company |
=====+========+===============+=======================|
| 1 | 297 | software engineer | x |
|----+--------+---------------+-----------------------|
| 2 | 297 | sr software engineer | y |
-------------------------------------------------------
education
=========================================================
| eid | UserId | title | institute |
=====+========+===============+=========================|
| 1 | 297 | computer science | p |
|----+--------+---------------+-------------------------|
| 2 | 297 | MS software engineering | q |
---------------------------------------------------------
Result
=====================================================================================================================================================================================
| userid | workex_title | company | workex_title | company | education | institute |education | institute |
=====+========+===============+======================================================================================================================================================|
| 297 | software engineer | x | sr software engineer | y | computer science | p |sr software engineer | q |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have a table with posts I want to schedule on Facebook. No schedule dates are stored here.
I have a second table with schedule dates based on week days. All hours are the same but not all weekdays are included. Some of them are missing.
| id | mon | tue | wed | thu | fri | sat | sun |
| --- | ----- | ----- | --- | ----- | --- | ----- | ----- |
| 1 | 10:20 | 10:20 | | 10:20 | | 10:20 | 10:20 |
| 2 | 15:25 | 15:25 | | 15:25 | | 15:25 | 15:25 |
| 3 | 18:25 | 18:25 | | 18:25 | | 18:25 | 18:25 |
| 4 | 21:25 | 21:25 | | 21:25 | | 21:25 | 21:25 |
| 5 | | | | | | | |
| 6 | | | | | | | |
| 7 | | | | | | | |
Let's say we are in the first day of the week (08:00) and I want to calculate the dates for the next 100 posts (5 weeks from now). I'm thinking I ought to get an array with all these dates in UNIX time.
$array = array('1439893200','1439896200','1439833200',......'1437893200','1449893200');
I need the array because I want to output the dates when I display the posts from the database. The posts can be reordered and the dates can be changed that's why I don't store the schedule dates there. I prefer a separate table for that.
I already spent a lot of time trying to achieve this but without success. Any starting advice and help will be appreciated.
How about we start in Wednesday when there are no scheduled hours?
we have this table "Categoris"
------------------------------------
| ID |parent.id | Category Name |
| 1 | 0 | php |
| 2 | 1 | Jquery |
| 3 | 2 | Java script |
| 4 | 2 | HTML |
| 5 | 4 | CSS |
| 6 | 1 | word Press |
| 7 | 3 | DOM |
Output should be
PHP->Jquery
->wordpres
Jquery->java Script
->HTML
Java Script->DOM
HTML-> CSS
Word Press
DOM
Have a look at PEAR's Tree package.