5 ways to secure quickly modify the MySQL database name
A single select statement realizes the number of MySQL query statistics
Where is the use of a single select statement to implement MySQL query counting times? There are too many uses.For example, in a transcript, you want to check the number of passers and those who fail.How can you check it out at once?
The simple statement of MySQL query statistics must be like this:
select a.name,count_neg,count_plus from
(select count(id) as count_plus,name from score2 where score >=60 group by name) a,
(select count(id) as count_neg,name from score2 where score <=60 group by name) b
where a.name=b.name
At least 2 sentences must be used.
I just came across today and discovered that mysql supports if, so use if creatively to achieve it:
select name, sum(if(score>=60, 1,0)),sum(if(score<60,1,0)) from score2 group by name
Single select statement realizes the simple method of MySQL query counting times.
The principle is that if it is greater than 60, it is assigned a value of 1, and then the sum is counted.
Count in Mysql query statistical function
Today I encountered a problem: Count all girls with scores greater than 90 and there is a total number
I just wrote this at the beginning: $sql="select girls scores from use where results> 90"; $result=mysql_query($sql);
$row=mysql_num_rows($result);echo "The total is: $row ";
But 100 pieces are okay, if it's 10,000 pieces, is it going to be very slow! ! Later, a friend told me to use the count function, which I just remembered.
Change the above sql statement to:
$sql="select count(*), girls' scores from use group by girls' scores having girls' scores> 90";
So the query statement will be much faster
0 Comments