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
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 two tables in MySQL. First is a Room.
and second is Reservation.
In Table reservation i have Room_Id and Reservation_DateFrom and Reservation_DateTo
How can i make a query that take two random dates for example (12-12-2012 and 21-12-2012) and see if the specific room is free all of the days from 12-12-2012 to 21-12-2012 if i have
DateFrom and DateTo for rooms in Reservation. I want to list all rooms that are available for rent on these days. For example if Room 1 has reservation from 15-12-2012 to 20-12-2012
it will not return it because some days from 12-12-2012 to 21-12-2012 are already reserved.
Thanks.
SELECT Ro.*
FROM Room Ro
WHERE NOT EXISTS (SELECT 1 FROM Reservation Re
WHERE Ro.Id = Re.Room_Id
AND ([yourStartDate] BETWEEN Re.Reservation_DateFrom AND Re.Reservation_DateTo
OR [yourEndDate] BETWEEN Re.Reservation_DateFrom AND Re.Reservation_DateTo)
)
it'll grab rooms that don't have any reservations that collide with your date range.
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 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
Table articles
id - content - ins_dt
1 - lorem ipsum1 - 2013-01-09
2 - lorem ipsum2 - 2013-02-08
3 - lorem ipsum3 - 2012-11-03
4 - lorem ipsum4 - 2011-01-20
5 - lorem ipsum5 - 2011-12-13
6 - lorem ipsum6 - 2010-05-12
With query
SELECT ins_dt FROM articles ORDER BY ins_dt DESC;
I get this: (http://sqlfiddle.com/#!2/fc9ea6/5)
"2013 2013 2012 2011 2011 2010"
But I need this:
"2013 2012 2011 2010"
Whatever the values you are getting store them in array
then $finaldata = array_unique($yourarray);
You can use simple SQL query
SELECT GROUP_CONCAT(DISTINCT YEAR(ins_dt)) AS `year`
FROM articles
ORDER BY ins_dt DESC;
Here is the sample and demo: http://sqlfiddle.com/#!2/fc9ea6/3
As you have the data in an array, you can easily use Array unique in your code, which will give you an array with only unique values in it.
Alternately, you could change your SQL to only pull the data you need from the table itself like this:
select distinct year from (select date_format(ins_dt, '%Y') from tableArticles) myData)
try sort http://php.net/manual/en/function.sort.php
sort($myarr['ins_dt'], SORT_NUMERIC);
print_r($myarr);
a little searching effort could land you on great links like this one
http://php.net/manual/en/array.sorting.php