zoukankan      html  css  js  c++  java
  • mysql使用存储过程, 给临时列创建索引排序,

    CREATE PROCEDURE `testOrgan`() 
    BEGIN
            DROP TABLE IF    EXISTS tmp_table;
    
            CREATE TEMPORARY TABLE `tmp_table`  (
          `city_code` varchar(32) DEFAULT NULL COMMENT '城市代码',
          `ins_code` varchar(32) DEFAULT NULL COMMENT '城市代码',
          `organ_type` varchar(12) DEFAULT NULL COMMENT '机构类型,H:医院;P:药店',
          `organ_name` varchar(64) NOT NULL COMMENT '机构名称',
          `organ_address` varchar(512) DEFAULT NULL COMMENT '机构地址',
          `organ_access_url` varchar(512) DEFAULT NULL COMMENT '机构跳转地址',
          `state` varchar(1) DEFAULT NULL COMMENT '状态',
          `longitude` double DEFAULT NULL COMMENT '经度',
          `latitude` double DEFAULT NULL COMMENT '维度',
          `area` varchar(32) DEFAULT NULL COMMENT '区域',
          `organ_category` varchar(32) DEFAULT NULL COMMENT '机构类目:医院资质、药店品牌',
          `adCode` varchar(32) DEFAULT NULL COMMENT '区域编码',
          `pyCode` varchar(32) DEFAULT NULL COMMENT '拼音首字母',
          `organ_catagery` varchar(20) DEFAULT NULL COMMENT '机构类别,现在区分少儿与成人。少儿:children',  
          `dis` double DEFAULT NULL COMMENT '距离',
          KEY `citycode` (`city_code`),
          KEY `inscode` (`ins_code`) USING BTREE,
          KEY `diS` (`dis`) USING BTREE
        ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '' ROW_FORMAT = Compact;
     
        insert into tmp_table(
                    city_code,
                    ins_code,
                    organ_type,
                    organ_name,
                    organ_address,
                    organ_access_url,
                    longitude,
                    latitude,
                    area,
                    organ_category,
                    adCode,
                    pyCode,
                    organ_catagery,
                    dis )  SELECT
                    city_code,
                    ins_code,
                    organ_type,
                    organ_name,
                    organ_address,
                    organ_access_url,
                    longitude,
                    latitude,
                    area,
                    organ_category,
                    adCode,
                    pyCode,
                    organ_catagery,    
                    ROUND(
                            6378.393 * 2 * ASIN(
                            SQRT(
                            POW(
                            SIN(
                            (
                            30.0
                            * PI() / 180 - latitude * PI() / 180
                            ) / 2
                            ),
                            2
                            ) +
                            COS(30.0 * PI() / 180) * COS(latitude * PI()
                            /
                            180) * POW(
                            SIN(
                            (
                            130.0 * PI() / 180 - longitude
                            * PI() / 180
                            ) / 2
                            ),
                            2
                            )
                            )
                            ) * 1000 * 1
                            )/1000 as dis                
                FROM
                    wh_institution  
                WHERE
                    city_code = 'SZ0755' and ins_code = 'SZHRSS'  and organ_type =
                    'P' and state = '1' ;
            
            
        SELECT
            city_code,
            ins_code,
            organ_type,
            organ_name,
            organ_address,
            organ_access_url,
            longitude,
            latitude,
            area,
            organ_category,
            adCode,
            pyCode,
            organ_catagery,
            dis from tmp_table order by dis;
    END 
  • 相关阅读:
    HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数
    HDU5596/BestCoder Round #66 (div.2) 二分BIT/贪心
    HDU 5596/BestCoder Round #66 (div.2) GTW likes math 签到
    BZOJ 1877: [SDOI2009]晨跑 费用流
    BZOJ 1452: [JSOI2009]Count 二维树状数组
    BZOJ 1143 1143: [CTSC2008]祭祀river 最长反链
    Codeforces Round #335 (Div. 2) D. Lazy Student 贪心
    Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS
    Codeforces Round #335 (Div. 2) A. Magic Spheres 模拟
    UVALive 6187 Never Wait for Weights 带权并查集
  • 原文地址:https://www.cnblogs.com/zyf-yxm/p/12097537.html
Copyright © 2011-2022 走看看