php quiz how to query 10 rows based on levels [closed] - php

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 7 years ago.
Improve this question
I have a table(quiz). And the fields are id,question,answer, and level.
There Many questions for level 1, many questions for level 2 and so on. Please how do i query 10 rows based on the levels consecutively i.e
question1(level 1)
question2(level 2)
question3(level 3)
..to
question10(level 10)
this is what i have so far:
$con->prepare("SELECT*FROM quiz WHERE level IN (1,2,3,4,5.....10) limit 0,10");
but the result i get is only 10 questions on level 1. Please i also want it to be random

Here's an attempt, though perhaps it needs a subquery:
SELECT * FROM quiz
WHERE level BETWEEN 1 AND 10
GROUP BY level
ORDER BY RAND(), level
Second attempt:
SELECT * FROM
(
SELECT * FROM quiz
WHERE level BETWEEN 1 AND 10
ORDER BY RAND()
) tmp
GROUP BY level
ORDER BY level

Related

Get products variation details [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 2 years ago.
Improve this question
I will developing e-commerce website but need some help from you.
When I run query "SELECT * FROM products_variations_option WHERE variations_id IN (31,41) ORDER BY product_variations_id ASC" then I am gating this output but I need 1 and second row, Means I want only product_variations_id= 75 because 31 and 41 both value found in only product_variations_id=75
The below query may give you desired output
SELECT variations_id, product_variations_id
FROM (SELECT *
FROM products_variations_option
WHERE variations_id IN (31,41)
ORDER BY product_variations_id ASC
) as t
GROUP BY variations_id

mysql query for my project (It has only 1 table named judge_review) which needs to sort out top 3 winners [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 5 years ago.
Improve this question
I have tried writing the below query but i just need 3 winners(1st,2nd and 3rd place) and my query has just brought every project in descending order but i need only top 3.
<SELECT judge_review.sub_ID, SUM(judge_review.avgPoints) AS TOTAL FROM judge_review GROUP BY judge_review.sub_ID ORDER BY TOTAL DESC>
You need to apply LIMIT 3
SELECT judge_review.sub_ID,
SUM(judge_review.avgPoints) AS TOTAL
FROM judge_review
GROUP BY judge_review.sub_ID
ORDER BY TOTAL DESC
LIMIT 3
Reference:- Limit Data Selections From a MySQL Database
To limit number of returned rows in the result set you have to specify number of that rows by adding to the end of the query LIMIT 3.

SQL Query to count number of rows searched until condition is met [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 6 years ago.
Improve this question
Just as the title says, I need a query to count the rows until the condition is met. Here's my setup:
partnumber
-----------
b
e
d
a
c
So if I'm going to search for partnumber = d it will sort the part number and return 4 (since d is the 4th when you sort the partnumber).
I can do this inside a loop. I'm just wondering if there is a query for this.
Thanks in advance
SELECT COUNT(*) FROM THE_TABLE WHERE partnumber <= (SELECT ID FROM THE_TABLE WHERE partnumber <= 'd');

Fetch mysql records where id is 0,10,20,30, etc [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 about 30 000 records in database, and I must create 10 cron jobs for these:
job 1 fetches records where column `id` is 0,10,20,30, etc.
job 2 fetches records where column `id` is 1,11,21,31, etc.
and so forth.
How can I approach this?
Use the modulo operator
select * from your_table
where id % 10 = 1
to get 1,11,21,31,... and so on. And
where id % 10 = 2
for 2,12,22,32,....

Need a little guidance on counting and calculating sum of rows. [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 9 years ago.
Improve this question
I'm making a little voting tool (voting from 1 to 5) and I have the votes stored in a DB. I'm wondering, what is the best manner to count all the rows (of a specific post ID) and then calculate the sum of those specific rows so that I can display the results.
i.e
Results: 3.5 / 5
(total votes: 1047)
Should I use a PHP loop or MYSQL sum?
SELECT AVG(vote), COUNT(vote) FROM vote_table WHERE post_id = 1234;
The first. column gives your average out of 5 and the count the total votes. To get all the stats at once:
SELECT AVG(vote), COUNT(vote), post_id FROM vote_table GROUP BY post_id;

Categories