mariadb:SQL日常使用总结
1.关联删除
DELETE T_Base_Resource_Action FROM T_Base_Resource_Action INNER JOIN T_Base_Resource ON T_Base_Resource_Action.permission = T_Base_Resource.permission
WHERE T_Base_Resource.resID=’course’ AND T_Base_Resource_Action.roleID=’service’ and T_Base_Resource_Action.rootOrgID=’3’;
如果用别名的话就会报错:1109 Unknown table 'T_Base_Resource_Action' in MULTI DELETE
2.查询分区
USE information_schema;
SELECT PARTITION_NAME,TABLE_ROWS
FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = 't_gps';
SELECT table_name,table_rows FROM TABLES
WHERE TABLE_SCHEMA = 't_gps'
ORDER BY table_rows DESC;
3.取最新的记录
select *,max(gpsDate) maxDate from t_gps
where gpsDate>='2018-08-29 00:00:00' and gpsDate<='2018-08-29 23:59:59'
group by carCard
备注:记得标准的SQL,非group字段不能放到select中
本文来自博客园,作者:huiy_小溪,转载请注明原文链接:https://www.cnblogs.com/huiy/p/9437898.html