Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have simple mysql table:
id server1 server2
1 Yes Yes
2 Yes No
3 No No
What I'm trying to do is calculate how many "Yes" and "No" are in each column and then use that number in charts (like highcharts)
select sum(server1 = 'Yes') as s1_yes,
sum(server2 = 'Yes') as s2_yes,
sum(server1 = 'No') as s1_no,
sum(server2 = 'No') as s2_no
from your_table
Use case statements like this
select server1,
sum(case when server1 = 'yes' then 1 else 0 end) as yes_count,
sum(case when server1 = 'no' then 1 else 0 end) as no_count
from yourtable
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to create an query to have the all matchs that a player win.
So, I have this table
ID_PLAYER1 ID_PLAYER2 SCORE_PLAYER1 SCORE_PLAYER2
1 4 5 3
2 1 3 4
3 4 2 0
I want to have this :
ID_PLAYER MATCH_WIN
1 2
2 0
3 1
4 0
Thank you !
I'm answering this because it's non-trivial and because I want to see if I can actually do it :p
SELECT `ID_PLAYER`, COUNT(*) AS `MATCH_WIN` FROM
(SELECT
IF(`SCORE_PLAYER1`>`SCORE_PLAYER2`, `ID_PLAYER1`, `ID_PLAYER2`) AS `ID_PLAYER`
FROM `your_table_name_here`
) AS `tmp`
GROUP BY `ID_PLAYER`
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the database as follows
Name | Area 1 | Area 2
XYZ 200 300
ZUX 0 0
YYZ 100 200
What I want to do is, count the number of rows where SUM of (Area 1 and Area 2) is not equal to 0. In the example mentioned, It's 2. (SUM has to be calculated virtually)
I tried to use different ways with Find(); Still no luck.
Try this:
<?php
$this->Model->find('count', array(
'conditions' => array(
'(Area1 + Area2) != ' => 0
)
));
// returns 2
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$nr333 = mysql_query("SELECT COUNT(*) AS cnt FROM (
SELECT * FROM games
WHERE human = '".mysql_real_escape_string($_GET[human])."'
ORDER BY id DESC LIMIT 100
) tmp WHERE changed = 'y'", $link) or die(mysql_error());
$frecventa333 = mysql_num_rows($nr333);
so bassicaly i dont get any error but .. instead of getting the real number i get just 1:|
http://s017.radikal.ru/i414/1310/a2/37958f7cdb48.png
That's because COUNT returns only one row, always. But in that row you'll find field with all rows counted, in one integer.
Try to fetch that row.
And next thing you should do is checking PDO extension. It's better than deprecated mysql_* functions and isn't so hard to learn.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to retrieve (stratageeks,HCL,IMIMobile) value from the table where user_id=wordpress how it possible
This is my Table
id user_id company_name number_save
---------------------------------------------------------------
1 wordpress Stratageeks 1
2 Manju Stratageeks 1
3 Manju Wipro 2
4 wordpress HCL 2
5 wordpress IMIMobiles 3
SELECT company_name FROM table WHERE user_id='wordpress'
You should consider learning basic SQL if you plan on doing this in the future.
If you want distinct results, use:
SELECT distinct company_name FROM table WHERE user_id='wordpress'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am using mysql as database and saved time as time stamp of related posts in table, now i want to fetch the post made rrecently . How can i compare and fetch the post made recently?
you can fetch rows in descending order of your column (time_stamp).
ex:
SELECT * FROM Table_Name ORDER BY col_time_stamp DESC;
col_time_stamp : is the column
select top 1 * from posts order by timestamp desc
try this
SELECT * FROM Table_Name ORDER BY col_time_stamp DESC LIMIT 0;