1.mysql 空间位置计算
##简单计算两个点的位置
##直接having笔记位置,不走空间索引
SELECT
locPoint,
st_distance_sphere(locPoint, point(118.36042290582,31.294304741753)) AS distance
FROM
`location`
HAVING
distance < 100 ORDER BY distance
##2.使用四点矩形定位法,走索引
##@度数转为米格式划算为1000米除以111,为得到的距离,例如100米为(0.1/111)
SELECT
locPoint,
st_distance_sphere(locPoint, point(118.36042290582,31.294304741753)) AS distance
FROM
location
WHERE
ST_Contains(ST_MakeEnvelope(
Point((118.36042290582+(0.1/111)), (31.294304741753+(0.1/111))),
Point((118.36042290582-(0.1/111)), (31.294304741753-(0.1/111)))
), locPoint)
ORDER by distance
查询无限分类所有父级
SELECT *
FROM ( SELECT @r AS _id,
(SELECT category_name FROM user_category WHERE id = _id) AS label,
(SELECT @r := parent_id FROM user_category WHERE id = _id) AS parent_id,
@l := @l + 1 AS lvl FROM (SELECT @r := 1722, @l := 0) vars,
user_category h WHERE @r != 0
) tmp
按条件汇总,聚合,去重统计各个数据
SELECT
COUNT(1) AS all_total,
COUNT(if( b.career = 0 ,1,null)) career_0_total,
COUNT(if( b.career = 1 ,1,null)) career_1_total,
COUNT( if( b.career = 2 ,1,null)) career_2_total,
COUNT(if( b.career = 3 ,1,null)) career_3_total,
COUNT(if( b.career = 4 ,1,null)) career_4_total,
COUNT(if( b.career = 5 ,1,null)) career_5_total,
IFNULL(sum(a.pay_total),0) all_sum,
IFNULL(sum(if( b.career = 0 ,a.pay_total,0)),0) career_0_sum,
IFNULL(sum(if( b.career = 1 ,a.pay_total,0)),0) career_1_sum,
IFNULL(sum(if( b.career = 2 ,a.pay_total,0)),0) career_2_sum,
IFNULL(sum(if( b.career = 3 ,a.pay_total,0)),0) career_3_sum,
IFNULL(sum(if( b.career = 4 ,a.pay_total,0)),0) career_4_sum,
IFNULL(sum(if( b.career = 5 ,a.pay_total,0)),0) career_5_sum,
IFNULL(count(DISTINCT a.userid),0) all_user,
COUNT(DISTINCT if( b.career = 0 ,a.userid,null)) career_0_user,
COUNT(DISTINCT if( b.career = 1 ,a.userid,null)) career_1_user,
COUNT(DISTINCT if( b.career = 2 ,a.userid,null)) career_2_user,
COUNT(DISTINCT if( b.career = 3 ,a.userid,null)) career_3_user,
COUNT(DISTINCT if( b.career = 4 ,a.userid,null)) career_4_user,
COUNT(DISTINCT if( b.career = 5 ,a.userid,null)) career_5_user,
IFNULL(avg(a.pay_total),0) all_avg,
IFNULL(avg(if( b.career = 0 ,a.pay_total,0)),0) career_0_avg,
IFNULL(avg(if( b.career = 1 ,a.pay_total,0)),0) career_1_avg,
IFNULL(avg(if( b.career = 2 ,a.pay_total,0)),0) career_2_avg,
IFNULL(avg(if( b.career = 3 ,a.pay_total,0)),0) career_3_avg,
IFNULL(avg(if( b.career = 4 ,a.pay_total,0)),0) career_4_avg,
IFNULL(avg(if( b.career = 5 ,a.pay_total,0)),0) career_5_avg
FROM
member_order a
LEFT JOIN user_register b ON a.userid = b.userid
WHERE
a.`status` = 1
mysql查看进程
show processlist;
kill pid;
##另外一种情况,执行alter table的时候卡死的时候,有可能是mysql有未提交的事务,查看进行中的事务的命令:
select * from information_schema.innodb_trx;