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 8 years ago.
Improve this question
My sample database query result looks like this.
ID Product Owner
1 iPhone Shanu
2 MotoX Shajan
3 HTC Amal
4 iPhone Jibi
5 MotoX Anil
6 iPhone Gregary
I like to get the number of each phones
I want the result like this:
iPhone 3
MotoX 2
HTC 1
This is a fairly basic query -
SELECT `product`, count(`product`)
FROM `table`
GROUP BY `product`;
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 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
So I have this database:
John 4.2
Robert 6
Maria 3.2
What I would want is lets say I refresh a website. And in every refresh I will get a random name from that database based on the chance of showing-> that would mean that Robert would appear more times than the other people(because of his chance)
Any way to do this? I just can't think of anything.
I've create your table with columns name and weight.
The following request return on name, depending on the weight:
SELECT name FROM table ORDER BY RAND()*weight DESC LIMIT 1;
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
I have a table named 'prices' and every range has its price.
course_id start end price
-----------------------------
1 1 5 20
1 5 10 18
1 10 100 15
-------------------------
I have for example $course_id = 1 and $weeks_num = 8.
How can I get the price of that course?
In the given example I should have 18 because 8 exists between 5 and 10.
You can use BETWEEN clause. http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_between
...
WHERE 8 BETWEEN start AND end
...
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 databade table as follows
id A
1 2
2 4
3 5
4 9
I want the result to show as below by doing repeated addition
A B
2 2
4 6
5 11
9 20
At this point, we're supposed to ask you what you've tried, but anyway...
SELECT x.a
, SUM(y.a) b
FROM my_table x
JOIN my_table y
ON y.id <= x.id
GROUP
BY x.id;
http://sqlfiddle.com/#!9/d66f6/1
SELECT a,
IF(#b IS NULL, #b:=a, #b:=#b+a) as B
FROM table1
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,....