SELECT with a chance of showing [closed] - php

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;

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 select from users where there are more matches [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
I would like to know how to choose the users that have the highest number of columns to match the columns of the logged in user.
order by sum matches conditions ex:
SELECT * FROM table where fColumn = 'name' and column2='value2' or colmun3='value3'
ORDER BY (
(column2='value2') + (column3='value3')
) DESC

Get the closest value of a column in MYSQL [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 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

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,....

Store area unit conversion in mysql table [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 8 years ago.
Improve this question
I have land buy/sell related website. So I want to store land area units in India and their conversion in other in units in mysql table. When user from specific area see properties list on website and if he selects acre in dropdown list then he can see the every property area in the acre though the property was listed in another unit.
So How Do I do this??
A simple two table can do this .. if you like..
Table 1:Units[id,UnitName]
Table 2:ConversionUnit[conversionId,fromUnitId,toUnitId,offset]
such as
table 1: [1,Centimetre],[2,Mitre],[3,kilometre]
table 2: [1,1,2,100],[1,3,1,0.000001]
First entry in the table to for converting CM to M and second row is to convert from KM to CM.
Hope it helps..

Categories