Query for showing the Passers from the database [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 3 years ago.
Improve this question
Student_ID | First_Name | Last_Name | Examination_date | Exam_grade
| | | |
12345 | John | Doe | 12/01/2019 | 5
67890 | Johny | Bravo | 12/02/2019 | 7
09876 | Johnny | Boy | 12/02/2019 | 3
Hello Good day, I just want to show only the students who passed the exam, that has a minimum grade of 5 above. Thank you so much
here's my query
$conn->query("SELECT * FROM tbl_admission where exam_grade > 5");

use this condition - where exam_grade >= 5
SELECT * FROM tbl_admission where exam_grade >= 5

For having grade 5 or above you should use >= in your query .
SELECT * FROM tbl_admission where exam_grade >= 5

Related

How to search in MySQL exploded array data [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 4 years ago.
Improve this question
My table structure as fallows
+----+------+---------+---------+
| id | name | heading | catid |
+----+------+---------+---------+
| 1 | ajay | xyz | 1:25:22 |
| 2 |sanjay| abc |15:25:45 |
+----+------+---------+---------+
If i get condition catid=22 then get result
+---+-----+----+---------+
| 1 | ajay| xyz| 1:25:22 |
+---+-----+----+---------+
If i get condition catid=15 then get result
+---+-----+----+----------+
| 2 | sanjay| abc|15:25:45|
+---+-----+----+----------+
If i get condition catid=25 then get result
+---+-----+----+----------+
| 1 | ajay| xyz| 1:25:22 |
+---+-----+----+----------+
| 2 | sanjay| abc|15:25:45|
+---+-----+----+----------+
You could use FIND_IN_SET, after replacing the colons in catid with commas:
SELECT *
FROM yourTable
WHERE FIND_IN_SET('25', REPLACE(catid, ':', ',')) > 0;
But a good long term investment would be to normalize the catid data and get those IDs in separate records.
There is also a way to do this using the LIKE operator, but it is ugly:
SELECT *
FROM yourTable
WHERE CONCAT(':', catid, ':') LIKE '%:25:%';

php mysql how to select what i need from 2 tables [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
how can i select data from 2 columns
i have table countrys:
country_id | country
--------------------
1 | England
2 | Poland
3 | Italy
and more...
and i have table Messages:
message_id | message | country_id
---------------------------------
1 | text.. | 1
2 | text.. | 2
3 | text.. | 1
1 | text.. | 3
and i need result like this:
message | country
--------------------
text.. | England
text.. | Poland
text.. | England
text.. | Italy
Query example please for my understand!
Try something like this as your select statement
SELECT message, country FROM Countrys AS c
INNER JOIN Messages as m on c.country_id = m.country_id;
Use Join
Select message,country From Messages m join countrys c
on m.country_id=c.country_id

Compare results of two queries laravel [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 two tables like below:
cat
+-------------------------------+
| id | 1 | 2 | 3 | 4 | 5 |
+-------------------------------+
| name | Hi | Ho | Hu | Ha | He |
+-------------------------------+
selected cat
+----------------+
| id | 2 | 5 |
+----------------+
| name | Ho | He |
+----------------+
Expected Output:
1 - > No
2 - > Yes
3 - > No
4 - > No
5 - > Yes
select id,
case when id in (select distinct id from selected_cat) then 'Yes'
else 'No' end
as somecol
from cat;
You can use a case statement to check for the existence of id in the other table.

Sum top three totals and group result by [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
Here is my problem...
table looks like this:
|id |coutry |sum
| 0 | USA | 30
| 1 | USA | 60
| 2 | USA | 90
| 3 | USA | 80
| 4 | GER | 40
| 5 | GER | 90
| 6 | SWE | 30
| 7 | SWE | 10
| 8 | SWE | 90
| 9 | SWE | 40
and result (top three scores if exists) should be like this:
|coutry |total
| USA | 230
| GER | 130
| SWE | 160
Any change to solve this by sql only? I'll fetch final result using php foreach..
The limit keyword should do the trick:
SELECT country, SUM(`sum`)
FROM my_table
GROUP BY country
ORDER BY 2 DESC
LIMIT 3
You need to establish a row number to get the top 3 sums per country. To do this with MySql, you have to use user-defined variables.
SELECT country, SUM(`sum`)
FROM (
SELECT *,
#rn:=IF(#prevCountry=country,#rn+1,1) rn,
#prevCountry:=country
FROM yourtable, (SELECT #rn:=0, #prevCountry:='') t
ORDER BY country, `sum` DESC
) t
WHERE rn <= 3
GROUP BY country
ORDER BY country
SQL Fiddle Demo
Try it here because #Mureinik have right.
SQL Fiddle
Order by country DESC solve "TOP" problem.

PHP code how to list the total value of each user [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 8 years ago.
Improve this question
table A
-----------------
a_id | user |
-----------------
1 |adam |
2 |jose |
3 |adam |
4 |adam |
5 |anne |
6 |jose |
table B
--------------------------------------
b_id | user | value1 | value2
--------------------------------------
1 |adam | 33 | 9
2 |jose | 46 |88
3 |adam | 77 |21
4 |adam | 81 |15
5 |anne | 11 |67
6 |jose | 45 |6
how can I view the total value of value1 and value2.
example: I want my list view page look like this.
--------------------------------------------------------
user | total value of value1 | total value of value2
---------------------------------------------------------
adam |191 | 45
jose |91 | 94
anne |11 | 67
pls. help.
You could always try some sort of aggregate query such as the following
SELECT user, SUM(value1) AS v1sum FROM B GROUP BY user

Categories