Search for time in mysql [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This id my table :
+------------+--------------+---------------------+--------+
| id | playduration | time | id_his |
+------------+--------------+---------------------+--------+
| 129 | 00:00:00 | 2014-01-19 04:08:00 | 1 |
| 190 | NULL | 2014-01-19 02:20:34 | 6 |
| 1390228962 | NULL | 2014-01-19 02:09:20 | 4 |
| 1390228963 | NULL | 2014-01-19 02:06:12 | 3 |
| 188 | NULL | 2014-01-19 02:00:11 | 5 |
| 151 | NULL | 2014-01-19 01:06:01 | 7 |
| 195 | NULL | 2014-01-15 01:10:00 | 2 |
+------------+--------------+---------------------+--------+
and i want to get row id = 1390228963 when I search for time = 2014-01-19 02:07:00
I thought that I have been explained it good

You need to get the last row before the time:
select t.*
from table t
where time <= '2014-01-19 02:07:00'
order by time desc
limit 1;

Just use this mysql query
SELECT * from tablename where time="2014-01-19 02:00:11";

Related

sum and group display in mySql PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 days ago.
Improve this question
I have a table below.
-----------------------------------------------
id | items | user | department | value | date |
-----------------------------------------
1 | books | john | dept-1 | 5 | 1-1-20
-----------------------------------------
2 | fruits | john | dept-1 | 10 | 3-1-20
-----------------------------------------
3 | books | rehman | dept-2 | 8 | 1-1-20
-----------------------------------------
4 | fruits | rehman | dept-2 | 20 | 9-1-20
-----------------------------------------
5 | woolens | john | dept-1 | 15 | 1-1-20
-----------------------------------------
6 | woolens | vinay | dept-1 | 9 | 3-1-20
-----------------------------------------
7 | veggies | sunil | dept-2| 20 | 10-1-20
-----------------------------------------
now I want to display these items like
department | user | value
--------------------------
dept-1 |
| john | 30
| vinay | 9
dept-2 |
| rehman | 28
| sunil | 20
how can I achieve this in mysql, this will be call in ajax and display in a table by php.
can someone help pls.
I tried doing grouping and used while loop but not able to execute desired output.

How to compare two tables and show every difference? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have 2 table with diferent data
Finance Orderan
+-----------------+ +---------------+
| id | no_order | | id| no_order |
+-----------------+ +---------------+
| 1 | 1234567890 | | 1 | 1234567890|
| 2 | 0987654321 | | 2 | 0987654321| |
| 3 | 1122334455 | | 3 | 1122334455|
| 4 | 1212121212 | | 4 | 2222222222|
+-----------------+ +---------------+
I want to return diferent data like this:
+-------------------------+
| no_order | no_order |
+-------------------------+
| 1212121212 | 2222222222 |
+-------------------------+
Maybe you need in simple
SELECT t1.no_order, t2.no_order
FROM Finance t1
JOIN Orderan t2 ON t1.id = t2.id
WHERE t1.no_order != t2.no_order
?

mysql - many to many query from bridge table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i have a task to complete. there is a many to many relationship. the bridge table has been made which looks like
left id right id
+----------+---------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
| 2 | 2 |
| 2 | 8 |
| 3 | 1 |
| 3 | 2 |
| 3 | 4 |
| 4 | 1 |
| 4 | 2 |
| 4 | 3 |
| 4 | 5 |
| 5 | 1 |
| 5 | 2 |
| 5 | 4 |
| 5 | 6 |
| 5 | 7 |
+----------+---------+
i have to display the left id = right id in one row
for example
for left id 1
left1 | right1 righ 2
for left id 3
left3 | right1 right2 right 4
how do i do this ? i have tried joining table , doesn't work
I think you can use a simple query to acheive this using GROUP BY and GROUP_CONCAT()
SELECT left_id, GROUP_CONCAT(right_id SEPARATOR ' ') as rigth_id
FROM left-right
GROUP BY left_id;
This is a reasonably straightforward application of GROUP_CONCAT() and GROUP BY. (http://sqlfiddle.com/#!9/ed7e1/2/0)
SELECT leftId,
GROUP_CONCAT(rightId ORDER BY rightId) rightIds
FROM bridge
GROUP BY leftId

Add one table's id to another table for specific value mysql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
+-----+---------------------+-------------+--------+
| OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | | 3000 |
| 100 | 2009-10-08 00:00:00 | | 1500 |
| 101 | 2009-11-20 00:00:00 | | 1560 |
| 103 | 2008-05-20 00:00:00 | | 2060 |
+-----+---------------------+-------------+--------+
Here i have a two table and i want to add one tables customer id to the another table , please help me on this
You can do it with SQL FOREIGN KEY Constraint on ALTER TABLE. You can see the documentation here.
ALTER TABLE first_table_name
ADD FOREIGN KEY (id)
REFERENCES second_table_name(CUSTOMER_ID)
It should work.

Migrate one column of a table to another table's column in phpmyadmin [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
field_data_body
+----------+---------------------+
| entry_id | body_value |
+----------+---------------------+
| 1009 | content |
+----------+---------------------+
| 1020 | |
+----------+---------------------+
| 1025 | more content |
+----------+---------------------+
i_posts
+------+---------------+
| id | html |
+------+---------------+
| 1009 | |
+------+---------------+
| 1020 | |
+------+---------------+
| 1025 | |
+------+---------------+
i_posts
+----------+---------------------+
| id | html |
+----------+---------------------+
| 1009 | content |
+----------+---------------------+
| 1020 | |
+----------+---------------------+
| 1025 | more content |
+----------+---------------------+
Hi, I'm trying to transfer the body_value column into the html column and am not sure how to execute this. I have a table called i_posts and I have all the id's of my posts that i'm trying to transfer. However in the field_data_body table it doesn't have content for every single entry_id. Is there a way to move the body_value into the html column while keeping the correct id? Thanks for any help in advanced!!
- Blake
Edit:
This is what you need.
UPDATE i_posts AS i, field_data_body AS f SET i.html = f.body_value WHERE i.id =f.entry_id
I did a small post about it.

Categories