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`
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 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
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
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 have two MySQL tables with the following...
Apps
ID | Name
1 App1
2 App2
and...
Minutes
ID | AppID | Amount
1 1 10
2 1 15
3 2 35
I want to pull the Apps and display them by time used. Should look like this...
App2 35 minutes
App1 25 minutes
How can I do this?
Thank you.
You can use a JOIN with a GROUP BY. To add the amounts together use the SUM aggregate funcion.
SELECT name, SUM(amount)
FROM `apps`
JOIN minutes ON `apps`.`id` = `minutes`.`appid`
GROUP BY `apps`.`id`
Use a JOIN (SQL):
SELECT
Apps.Name,
Minutes.AppID,
SUM(Minutes.Amount)
FROM Minutes
INNER JOIN Apps ON Apps.ID = Minutes.AppID
GROUP BY Apps.Name, Minutes.AppID
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
As MySQL/PHP Noob I am struggeling to solve the following:
Table called "cars"
Fields called "modell" and "engine"
|Modell |engine
=====================
|Volvo |2,0
|Volvo |2,6
|Volvo |2,0
|Saab |1,8
|Saab |2,1
|Saab |1,8
|Saab |1,8
|Chevrolet |4,2
Would like to write a question and get as answer:
Here are:
2 volvo with 2,0 engine
1 volvo with 2,6 engine
3 saab with 1,8 engine
1 saab with 2,1 engine
1 Chevrolet with 4,2 engine
SELECT count(*) AS count,
Modell,
engine
FROM cars
GROUP BY Modell,engine
select modell, engine, count(*) as cnt
from cars
group by modell, engine
SELECT COUNT(*),Modell,ENGINE FROM cars GROUP BY modell,ENGINE