Mysql import .sql file
- Access to the database (to import database)
- Database has to import database .sql file name, not the new.
- source path + filename
souce /home/robot/csql.sql
Database file .sql files in / home / robot directory
Delete the database data according to the time
DELETE FROM table WHERE time> = start time period AND <= End Time
Example:
mysql> DELETE FROM EnvironmentRealData WHERE SmpDatetime >= '2019-07-01 00:00:00' AND SmpDatetime <= '2019-07-02 00:00:00'
-> ;
Query OK, 145 rows affected (0.01 sec)
mysql>
Ordered by time:
SELECT Rainfall FROM EnvironmentRealData ORDER BY SmpDatetime DESC;
SELECT SmpDatetime,Temprature,Humidity,WindSpeed,WindSpeed,WindDirection,Pressure,Rainfall FROM EnvironmentRealData ORDER BY SmpDatetime DESC
Inserting data from one table to another table:
Provided that: the same field two tables
Example: Create a table PointType you want to inherit Num Num field information devicespotrobotinfo table:
INSERT INTO target table (Field 1, Field 2, ...) SELECT field 1, field 2, ... FROM table origin
Into the database:
the INSERT the INTO PointType (the Num) from the SELECT the Num devicespotrobotinfo;
To delete a column is empty rows:
delete from PointType where Num is null;
Check this column Num repeating:
SELECT Num,COUNT(*) FROM PointType GROUP BY Num HAVING COUNT(*) > 1;
Delete duplicate data in the table:
DELETE FROM PointType WHERE Num IN( SELECT Num FROM( SELECT Num,COUNT(*) FROM PointType GROUP BY Num HAVING COUNT(*) > 1 ) AS a ) LIMIT 1;