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 a table that holds prices, the idea behind it is to have users suggest prices they think are reasonable for a good,example; range
You can divide the price by the range size, and then use FLOOR() to get the beginning of the range:
SELECT 1500*FLOOR(price/1500) AS price_base, COUNT(*) AS count
FROM yourTable
GROUP BY price_base
ORDER BY count DESC
For example, price_base = 3000 contains all prices from 3000 to 4499, while price_base = 4500 contains all prices from 4500 to 5999.
Related
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
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.
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 a table "selled" which has three column id, qty, code how to sum all the values in qty column where code = X, I know how to count the number of rows in this column but I want to get the sum of the values inside these rows.
I am sorry guys i am still beginner and i really appreciate it ,This is the code i am using and it still not working
$query="SELECT SUM (qty) as sum_of_qty from selled WHERE code='$code'";
$result=mysqli_query($connection,$query);
$row=mysqli_fetch_assoc($result);
echo $row['sum_of_qty'];
Use the SUM function. Docs:
https://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_sum
SELECT SUM(qty) as sum_of_qty FROM selled WHERE code = x
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 that have a CP value (numeric), for example, 28030, 28060, 27100 etc. And the user can introduce a number via PHP. I want to, having this number for example, 28050, order in MYSQL my table putting 28060 as the first position.
This is the basic of my table:
SELECT * FROM `tiendas` ORDER BY `CP`
ABS() will work. Here's a query that does the job:
SELECT
CP
FROM tiendas
ORDER BY ABS(CP- 28050) ASC
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;