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
?>
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 am getting price values from mysql database table with the given php code
$sql="SELECT DISTINCT (price) FROM 'table' order by price asc";
$res=mysql_query($sql);
while($row=mysql_fetch_array($res))
{
$price=number_format($row[price]);
}
$price=implode(',',$price);
The result is 2,299,4,600,5,800,8,000,12,700,16,900,23,978,27,098
but i want to display the result as
$2,500 or less,$5,000 or less,$7,500 or less,$10,000 or less,$15,00 or less,$20,000 or less,$25,000 or less,$30,000 or less
Can anyone tell me how o fix this problem
$price = '$' . number_format(ceil($row['price']/2500.0)*2500) . ' or less';
The ceil function takes a floating-point number and returns the next-highest integer. By dividing by 2500.0 and then multiplying again, we get the next-highest multiple of 2500.
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
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'