I have a string like this 67,73,89. I want to explode all the value and compare each value. In php I can do it like this
<?php
$marks = "67, 73, 89";
$explode = explode(", ",$marks);
foreach($explode as $mark){
if($mark > 80)
echo $mark."<br>";
}
?>
Can anyone give me the mysql code so that i can select all the student roll number where marks contains atleast one value > 80.
You can use mysql explode function like this...
CREATE FUNCTION explode(str VARCHAR(255), delim VARCHAR(12), pos INT)
RETURNS VARCHAR(255)
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(str, delim, pos),
LENGTH(SUBSTRING_INDEX(str, delim, pos-1)) + 1),
delim, '');
Table structure is
╔═════════╦═══════╦══════════╗
║ Roll_No ║ Name ║ Marks ║
╠═════════╬═══════╬══════════╣
║ 1 ║ John ║ 67,73,89 ║
║ 2 ║ Bob ║ 75,69,80 ║
║ 3 ║ Smith ║ 62,79,92 ║
╚═════════╩═══════╩══════════╝