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 8 years ago.
Improve this question
I stored the month name in database as string which looks like
Apr-2013
May-2013
...
How could i sort the table month wise ?
Any help is appreciated.
You will have to format the date in order to sort it:
select aDate from t
order by str_to_date(aDate,'%b-%Y')
This is very inefficient, though. I'd recommend you to update that field and make it a date field or at least two ints: one for the month and one for the year. Then, if you need to get the name of the month you could use the monthname(date) function.
SELECT
*
FROM
dates
ORDER BY
STR_TO_DATE(date, '%b-%Y')
SQL Fiddle
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 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 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 can't find an answer to my question, it's probably easy but... anyway!
I have a database with every NHL game for one specific team in a table. Every game has been entered in the good order.
On my home page, I would like to display the upcoming game as well as the result of the previous game. How can I create a mySQL query to display the previous game based on today's date?
Thanks!
Do your game records have a timestamp or datetime value?
If so you could write a query ordering your games by the date smaller that now() and limit by one.
The query should look like this:
select * from games where gamedate < now() order by gamedate desc limit 1
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 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;