Get Results of Betting System Points using MySQL and PHP [closed] - mysql

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 days ago.
Improve this question
I'm designing online betting system. There are 60 players and 20 bettors. The person who bet the most points gets the corresponding player. The bettor can choose 3 players who have bet the most. One player can have only one bettor. How to write a mysql query to select the players with the most points and those who bet on them?
Using MySQL and PHP.
SELECT bet.bet_id, player.p_name, streamer.s_name, bet.points
FROM player
INNER JOIN bet ON player.p_id = bet.p_id
INNER JOIN streamer ON bet.s_id = streamer.s_id;
bet_id
p_name
s_name
points
1
fgh
sada
200
2
New 1Player
sada
3053
3
sad
ind
987
4
New 1Player
ind
3200
12
dgsrg
ind
6
13
newest
ind
45

Related

How to identify entries with all completed tasks? [closed]

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 5 years ago.
Improve this question
Let's say i have a table Task_status like below:
id TaskId SubTaskId status
1 1 1 Complete
2 1 2 Complete
3 1 3 Complete
4 2 4 InProgress
5 2 5 Complete
I want to find all the taskId whose all child tasks are Complete. How can I write that query?
Use group by and having to check if the number of rows per task equal the number of rows with Complete status.
select taskId
from tbl
group by taskId
having count(*) = sum(status='Complete')

SQL Query Joins [closed]

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
I have a table as follows:
name week effort
quentin 1 1
quentin 1 2
quentin 2 1
tracy 1 1
joe 2 2
There will only be a handful of unique names so it doesn't need to be dynamic
And I would like to query it to return something like
week QuentinEffortSum TracyEffortSum JoeEffortSum
1 3 1 0
2 1 0 2
I have tried something along the lines of
SELECT SUM(Effort) AS JoeEffort, Min (Week) AS week FROM [Group$]
WHERE name = "Joe"
GROUP BY week
ORDER By week
which returned:
week JoeEffort
1 3
2 1
and now I need the other columns and imagine in involves joins but am not sure how to complete the task
Please help
Thanks
I think a PIVOT table would work, like so:
SELECT *
FROM (
SELECT
week,name,effort
FROM [Group$]
) as s
PIVOT
(
SUM(effort)
FOR [name] IN ('quentin','joe','tracy')
)AS pvt

SQL Sum of column based on other Column [closed]

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
Unfortunately My tables will be poor and I have no idea how to fix that. Essentially I have this table and I want to sum all the values on the right based on one value on the left. This is sample data but it will be 400+ records in the database. So if the numbers on the left are IDs for customers, and the numbers on the right are products purchased, how do I get a summary of products purchased per customer?
1 4
1 2
2 3
3 2
2 4
1 1
3 2
1 3
The final result would need to look like this:
1 10
2 7
3 4
SELECT
user_table.userID,
SUM(user_table.prodcut_purchase)
FROM
user_table
GROUP BY
user_table.userID

SELECT / GROUP BY - segments of time (30 minutes) [closed]

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
I'm trying to get my code to output in the following format:
2015-05-24 19:00 | 1
2015-04-24 19:30 | 3
2015-04-24 10:39 | 51
My table
rm_id | date
1 | 1298027046
2 | 1298027100
What should I do a SQL query?
Divide the timestamps by 1800 (30 minutes * 60 seconds/minute) to get the grouping.
SELECT FROM_UNIXTIME(1800 * FLOOR(date/1800)) AS period_start, COUNT(*) AS count
FROM YourTable
GROUP BY period_start
Ok thanks. It's great. still I need to add the condition of two dates. The first parameter will be administered and the second is the first + 7 days

How to remove records in mysql database? [closed]

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 want to remove records length equal to two. Is there any direct query to remove those records? Reading raw by raw and delete take huge time. Because my database contain more than 4 million records.
ID Column1
1 abcde bgrft
2 ab
3 bgtyk
4 gh
I want to delete record 2 and 4. Because that size=2.
I'm assuming that by 'size' you mean string length
delete from mytable where length(Column1) = 2