mysql常用操作
小明 Lv6

查询数据库所有的表

(用逗号隔开)

1
SELECT GROUP_CONCAt( table_name ) FROM information_schema.TABLES WHERE table_schema = '数据库名' AND table_type = 'base table';

查询数据库中某张表所有的字段

(用逗号隔开)

1
SELECT GROUP_CONCAT( column_name ) FROM information_schema.COLUMNS WHERE table_name = '表名';

计算两个经纬度之间的距离,lon经度,lat纬度

1
2
3
4
5
6
7
8
9
10
11
CREATE DEFINER=`lkhd`@`%` FUNCTION `func_distance`( 
lon1 DOUBLE,
lat1 DOUBLE,
lon2 DOUBLE,
lat2 DOUBLE
) RETURNS double
RETURN 6371 * acos(
cos(radians(lat1)) * cos(radians(lat2)) * cos(
radians(lon2) - radians(lon1)
) + sin(radians(lat1)) * sin(radians(lat2))
)
 评论