Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I want something like this:
Table
And my database table is like this:
Database
How can I get this records group by (hour and post) at the same time?
And How can I print this results on html?
SELECT post_id, hour, COUNT(*) FROM <table_name> GROUP BY post_id, hour
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a piece of code below and according to a condition I wanted to know why the question is invalid
CREATE VIEW HotelBookingCount (hotelNo, bookingCount)
AS SELECT h.hotelNo, COUNT(*)
FROM Hotel h, Room r, Booking b
WHERE h.hotelNo = r.hotelNo AND r.roomNo b.roomNo
GROUP BY h.hotelNo;
The question is :
SELECT hotelNo
FROM HotelBookingCount
WHERE bookingCount > 1000;
When I type it shows error
What is the logic behind this? Why I am not supposed to do this?
You can't have VIEWs that way and also there is nothing to pass the arguments as they are unused. Try with -
CREATE VIEW HotelBookingCount
AS SELECT h.hotelNo, COUNT(*) bookingCount
FROM Hotel h, Room r, Booking b
WHERE h.hotelNo = r.hotelNo AND r.roomNo b.roomNo
GROUP BY h.hotelNo;
Then
SELECT hotelNo
FROM HotelBookingCount
WHERE bookingCount > 1000;
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to get data from database from specific row to last row.
How can I do it?
You can set limit and offset with your sql query like this.
SELECT *
FROM your_table
ORDER BY id DESC
LIMIT 1, 1;
See more : http://www.mysqltutorial.org/mysql-limit.aspx
$sql="Select * from table order by id desc limit 20";//It will give you last 20 records
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
What's wrong with this query and how can i output the result?
`SELECT sum(BM) from (SELECT rpdc.BM from rpdc LIMIT $start, $limit) as totalbm`
You need to give an alias for the sum something as
SELECT
sum(BM) as total_sum
from (SELECT rpdc.BM from rpdc LIMIT $start, $limit) as totalbm
Then in php you can use as
$row['total_sum'];
Hey you need to add as 'some_name' like SELECT name as firstname
Replcae with this sum(BM) as total
So, result array will treat total_sum as key of array.
You can use it as $result['total']
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have this query:
$sql = $link->query("SELECT m.id_rel, (SELECT SUM(visita) as total FROM icar_mas_vistas WHERE id_rel = m.id_rel), icar_categorias.nombre
FROM icar_mas_vistas AS m, icar_categorias WHERE m.id_rel = icar_categorias.id_categoria");
if($sql->num_rows){
while($row = $sql->fetch_object()){
echo ''.$row->total.' '.$row->nombre.'';
}
It's working great in the SQL console, but when printing in PHP the value of total is not showing, how can i print it?
Thanks
Try change query adding AS total after brackets, to:
SELECT m.id_rel,
(SELECT SUM(visita) as total FROM icar_mas_vistas WHERE id_rel = m.id_rel) AS total, icar_categorias.nombre
FROM icar_mas_vistas AS m, icar_categorias
WHERE m.id_rel = icar_categorias.id_categoria
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
So I would like to know how I would get something like this..
There are 7 Members Online
Using my Timestamp which is set as format
2016-04-25 19:27:00
I would like this to be within a 30 min gap. This is how I tried it, But it did not work.
<?php $logged = mysql_query("SELECT COUNT(time) FROM users where time >= 600 ;") or die(mysql_error()); ?>
There are <?php echo $logged; ?> Members Online
SELECT COUNT(*) as theCount
FROM users
where login_time + interval 30 minute >= now()