1,字符串截取拼接

CONCAT(),'****');
SUBSTRING_INDEX(c.context,'}',1);
SUBSTRING_INDEX(a.task_context,':',-1) as context;

2,Case函数

(
        CASE a.type_code
        WHEN 'bp' THEN
            '血压'
        WHEN 'hr' THEN
            '心率'
        WHEN 'fbg' THEN
            '空腹血糖'
        WHEN '2hpbg' THEN
            '餐后两小时血糖'
        WHEN 'tc' THEN
            '总胆固醇'
        WHEN 'bua' THEN
            '血尿酸'
        WHEN 'bmi' THEN
            '体质指数'
        ELSE
            '其他'
        END
    ) AS type_code

3,字符串拼接

CONCAT_WS('/',b.value1,b.value2,b.value3);
CONCAT(a.value1,'mmol/L') AS value1

4,日期加减

DATEDIFF(DATE(MAX(take_time)),DATE(MIN(take_time))) as days

5,年龄计算

YEAR (NOW()) - YEAR (b.birthday) AS birthday

6,IF函数

,'女','男') AS gender

7,COUNT函数

)

8,外联

SELECT
    f.id,
    f.store_name,
    f.vendor_name,
    f.area_name,
    f.store_phone,
    h.realname,
    h.mobile,
    f.created_time
FROM
    (
        SELECT
            a.id,
            a.store_name,
            c.vendor_name,
            b.area_name,
            a.store_phone,
            a.created_time
        FROM
            pd_store a,
            pd_vendor_area b,
            pd_vendor c
        WHERE
            a.vendor_area_id = b.id
        AND a.vendor_id = c.id

        AND b.area_name LIKE '%%'
        LIMIT ,
    ) f
LEFT OUTER JOIN pd_clerk g ON f.id = g.store_id

LEFT OUTER JOIN pd_user h ON g.user_id = h.uid

9, 外联

SELECT
    k.operater_id,
    k.realname,
    k.mobile,
    k.pdNum,
    l.operater_id,
    l.realname,
    l.mobile,
    l.dslNum
FROM
    (
        SELECT
            a.operater_id,
            b.realname,
            b.mobile,
            COUNT(DISTINCT a.user_id) AS pdNum
        FROM
            pd_indicator_values a,
            pd_user b,
            pd_user_vendor c
        WHERE
            a.operater_id = b.uid

        AND a.type_code <> 'hr'
        AND a.user_id = c.user_id
        AND a.take_time >= '2016-10-26 00:00:00'
        AND a.take_time <= '2016-11-30 23:59:59'

        AND c.vendor_member_id LIKE '202%'
        GROUP BY
            a.operater_id
    ) k
LEFT OUTER JOIN (
    SELECT
        a.operater_id,
        b.realname,
        b.mobile,
        COUNT(DISTINCT a.user_id) AS dslNum
    FROM
        pd_indicator_values a,
        pd_user b,
        pd_user_vendor c
    WHERE
        a.operater_id = b.uid

    AND a.type_code <> 'hr'
    AND a.user_id = c.user_id
    AND a.take_time >= '2016-10-26 00:00:00'
    AND a.take_time <= '2016-11-30 23:59:59'

    AND c.vendor_member_id NOT LIKE '202%'
    GROUP BY
        a.operater_id
) l ON k.operater_id = l.operater_id
UNION
    SELECT
        k.operater_id,
        k.realname,
        k.mobile,
        k.pdNum,
        l.operater_id,
        l.realname,
        l.mobile,
        l.dslNum
    FROM
        (
            SELECT
                a.operater_id,
                b.realname,
                b.mobile,
                COUNT(DISTINCT a.user_id) AS pdNum
            FROM
                pd_indicator_values a,
                pd_user b,
                pd_user_vendor c
            WHERE
                a.operater_id = b.uid

            AND a.type_code <> 'hr'
            AND a.user_id = c.user_id
            AND a.take_time >= '2016-10-26 00:00:00'
            AND a.take_time <= '2016-11-30 23:59:59'

            AND c.vendor_member_id LIKE '202%'
            GROUP BY
                a.operater_id
        ) k
    RIGHT OUTER JOIN (
        SELECT
            a.operater_id,
            b.realname,
            b.mobile,
            COUNT(DISTINCT a.user_id) AS dslNum
        FROM
            pd_indicator_values a,
            pd_user b,
            pd_user_vendor c
        WHERE
            a.operater_id = b.uid

        AND a.type_code <> 'hr'
        AND a.user_id = c.user_id
        AND a.take_time >= '2016-10-26 00:00:00'
        AND a.take_time <= '2016-11-30 23:59:59'

        AND c.vendor_member_id NOT LIKE '202%'
        GROUP BY
            a.operater_id
    ) l ON k.operater_id = l.operater_id;

N,其他

SELECT
  b.store_name,
  a.take_time,
  c.realname,
  CONCAT(),'****'),
  c.mobile,
  (
        CASE a.type_code
        WHEN 'bp' THEN
            '血压'
        WHEN 'hr' THEN
            '心率'
        WHEN 'fbg' THEN
            '空腹血糖'
        WHEN '2hpbg' THEN
            '餐后两小时血糖'
        WHEN 'tc' THEN
            '总胆固醇'
        WHEN 'bua' THEN
            '血尿酸'
        WHEN 'bmi' THEN
            '体质指数'
        ELSE
            '其他'
        END
    ) AS type_code,
  a.value1,
  a.value2,
  a.value3,
  d.realname as clerkname,
  d.mobile as clerkmobile
FROM
    pd_indicator_values a,
    pd_store b,
    pd_user c,
    pd_user d
WHERE
    a.store_id = b.id
AND a.user_id = c.uid
AND a.operater_id = d.uid

AND a.take_time >= '2016-09-01 00:00:00'
AND a.take_time < '2016-11-01 00:00:00';
SELECT
    a.realname,
  a.gender,
  c.realname as clerkname,
  c.mobile,
  d.store_name,
  b.type_code,
  b.take_time,
  CONCAT_WS('/',b.value1,b.value2,b.value3)
FROM
    pd_user a,
    pd_indicator_values b,
    pd_user c,
    pd_store d
WHERE
    a.uid = b.user_id
AND b.operater_id = c.uid
AND b.store_id = d.id ORDER BY b.user_id ASC;
SELECT
    COUNT(*)
FROM
    (
        SELECT
            user_id,
            COUNT(user_id) AS coun,
            DATEDIFF(
                DATE(MAX(take_time)),
                DATE(MIN(take_time))
            ) AS days
        FROM
            pd_indicator_values
        WHERE
            take_time >= '2015-11-01 00:00:00'
        AND take_time <= '2016-11-24 23:59:59'

        GROUP BY
            user_id
        HAVING
            coun 

    ) k;
SELECT
    h.vendor_name,
    h.take_time,
    h.realname,
    h.created_time,
    h.gender,
    h.birthday,
    h.address,
    h.mobile,
    h.id_card,
    h.type_code,
    h.value1_status,
    h.value1,
    h.value2_status,
    h.value2,
    h.value3_status,
    h.value3,
    h.clerkname,
    h.clerkmobile,
    h.store_name,
    j.realname as stoname,
    j.mobile as stomobile
FROM
    (
        SELECT
            e.vendor_name,
            a.take_time,
            f.created_time,
            b.realname,
            (
                CASE b.gender
                ' THEN
                    '女'
                ' THEN
                    '男'
                ELSE
                    ' '
                END
            ) AS gender,
            YEAR (NOW()) - YEAR (b.birthday) AS birthday,
            g.address,
            b.mobile,
            b.id_card,
            (
                CASE a.type_code
                WHEN 'bp' THEN
                    '血压'
                WHEN 'hr' THEN
                    '心率'
                WHEN 'fbg' THEN
                    '空腹血糖'
                WHEN '2hpbg' THEN
                    '餐后两小时血糖'
                WHEN 'tc' THEN
                    '总胆固醇'
                WHEN 'bua' THEN
                    '血尿酸'
                WHEN 'bmi' THEN
                    '体质指数'
                ELSE
                    '其他'
                END
            ) AS type_code,
            (
                CASE a.value1_status
                ' THEN
                    '正常'
                ' THEN
                    '风险'
                ' THEN
                    '危险'
                ' THEN
                    '偏小风险'
                ' THEN
                    '偏小危险'
                ELSE
                    '其他'
                END
            ) AS value1_status,
            a.value1,
            (
                CASE a.value2_status
                ' THEN
                    '正常'
                ' THEN
                    '风险'
                ' THEN
                    '危险'
                ' THEN
                    '偏小风险'
                ' THEN
                    '偏小危险'
                ELSE
                    '其他'
                END
            ) AS value2_status,
            a.value2,
            (
                CASE a.value3_status
                ' THEN
                    '正常'
                ' THEN
                    '风险'
                ' THEN
                    '危险'
                ' THEN
                    '偏小风险'
                ' THEN
                    '偏小危险'
                ELSE
                    '其他'
                END
            ) AS value3_status,
            a.value3,
            c.realname AS clerkname,
            c.mobile AS clerkmobile,
            d.store_name,
            d.id,
      q.cou
        FROM
            (
                SELECT
                    o.user_id,
                    COUNT(o.user_id) AS cou
                FROM
                    pd_indicator_values o
                WHERE
                    o.take_time >= '2015-06-01 00:00:00'
                AND o.take_time <= '2016-11-22 23:59:59'
                GROUP BY
                    o.user_id
                HAVING
                    cou
            ) q,
            pd_indicator_values a,
            pd_user b,
            pd_user c,
            pd_store d,
            pd_vendor e,
            pd_user_vendor f,
            pd_user_info g
        WHERE
            q.user_id = a.user_id
        AND a.user_id = b.uid
        AND a.operater_id = c.uid
        AND a.store_id = d.id
        AND a.vendor_id = e.id
        AND a.user_id = f.user_id
        AND a.user_id = g.user_id
        AND a.take_time >= '2015-06-01 00:00:00'
        AND a.take_time <= '2016-11-22 23:59:59'
    ) h,
    pd_clerk i,
    pd_user j
WHERE
    h.id = i.store_id

AND i.user_id = j.uid ORDER BY h.cou DESC;

1,将查询结果存入表
insert into pd_temp select * from pd_other;

2,将表数据导出xls文件最大1048576记录数
select * from pd_temp limit 1048576,364387 into outfile 'c:\\20.xls';
3,格式转换
记事本另存为ASCII格式

iconv -futf8 -tgb2312 -otest 21.xls 20.xls

SELECT
    a.take_time AS take_time,
    b.realname AS realname,
    ,'女','男') AS gender,
    b.mobile AS mobile,
    b.id_card AS id_card,
    IF(a.type_code='fbg', '空腹血糖', '餐后两小时血糖') AS type_code,
    CONCAT(a.value1,'mmol/L') AS value1,
    d.realname as clerkname,
  d.mobile as clerkmobile,
    c.store_name AS store_name
FROM
    pd_indicator_values a,
    pd_user b,
    pd_store c,
    pd_user d
WHERE
    a.user_id = b.uid
AND a.operater_id = d.uid
AND a.store_id = c.id

AND a.take_time >= '2016-08-01 00:00:00'
AND a.take_time < '2016-09-01 00:00:00'
AND (
    a.type_code = 'fbg'
    OR a.type_code = '2hpbg'
)
AND (
    a.value1_status 

);
SELECT
    d.id,
    d.store_name,
    c.realname,
    c.mobile,
    count(a.caller_user_id),
    count(

    ),
    ),
    SUM(a.caller_duration)
FROM
    pd_call_records a,
    pd_clerk b,
    pd_user c,
    pd_store d
WHERE
    a.caller_user_id = b.user_id
AND b.user_id = c.uid
AND b.store_id = d.id
AND a.created_time >= '2016-08-01 18:48:45'
GROUP BY
    a.caller_user_id;
SELECT
    c.realname,
    c.mobile,
    SUBSTRING_INDEX(c.context, ),
    c.callednum,
    c.callnum,
    c.calltime,
    d.realname,
    f.store_name,
    d.mobile
FROM
    (
        SELECT
            b.realname AS realname,
            b.mobile AS mobile,
            SUBSTRING_INDEX(a.task_context, ) AS context,

        , , ) AS callednum,

    , , ) AS callnum,
    IFNULL(a.called_duration, ) AS calltime,
    a.caller_user_id AS clerkid
FROM
    pd_call_records a,
    pd_user b
WHERE
    a.called_user_id = b.uid

    ) c,
    pd_user d,
    pd_clerk e,
    pd_store f
WHERE
    c.clerkid = d.uid
AND d.uid = e.user_id
AND e.store_id = f.id;
SELECT COUNT(k.user_id) from (
SELECT
  a.user_id,
    DATEDIFF(DATE(MAX(a.take_time)),DATE(MIN(a.take_time))) as days
FROM
    pd_indicator_values a
WHERE
    a.vendor_id
AND a.take_time >= '2016-10-26 00:00:00'
AND a.take_time <= '2016-11-30 23:59:59'
GROUP BY a.user_id

)k 

SQL函数的更多相关文章

  1. Oracle 中的sql函数以及分页

    SELECT LPAD(,'*.') "LPAD example" FROM DUAL; 1.分页查询 (1)方法一:使用  between  and 来实现分页 select * ...

  2. SQL函数说明大全

    一旦成功地从表中检索出数据,就需要进一步操纵这些数据,以获得有用或有意义的结果.这些要求包括:执行计算与数学运算.转换数据.解析数值.组合值和聚合一个范围内的值等. 下表给出了T-SQL函数的类别和描 ...

  3. oracle(sql)基础篇系列(一)&mdash;&mdash;基础select语句、常用sql函数、组函数、分组函数

        花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...

  4. [转]字符型IP地址转换成数字IP的SQL函数

    使用SQL函数可以实现许多的功能,下面为您介绍的是字符型IP地址转换成数字IP的SQL函数示例,供您参考,希望对您学习SQL函数能够有所帮助.      /**//*--调用示例       sele ...

  5. 常用的Sql 函数

    常用的Sql 函数 1: replace 函数,替换字符. 语法 replace (original-string, search-string, replace-string ) 第一个参数你的字符 ...

  6. 常用的 SQL 函数

    SQL 函数 聚合函数(针对数字列): AVG:求平均分  COINT: 计算个数  MAX: 求最大值  MIN: 求最小值  SUM: 求和 数学函数():  ABS:     绝对值  CEIL ...

  7. Oracle数据库--SQL函数

    Oracle SQL函数  1.ASCII返回与指定的字符对应的十进制数;SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii( ...

  8. 常用的sql函数

    常用的sql函数 concat('hello','world') 结果:helloworld  作用:拼接 substr('helloworld',1,5)      hello           ...

  9. ThinkPHP使用SQL函数进行查询

    //SQL函数查询 $products=$pro->where(array("FIND_IN_SET('".$type."',type)",'num'=& ...

  10. oracle PL/SQL(procedure language/SQL)程序设计(续集)之PL/SQL函数

    PL/SQL函数 examples:“ 构造一个邮件地址 v_mailing_address := v_name||CHR(10)||                                 ...

随机推荐

  1. spring-test测试demo

    如果是maven项目,pom中增加如下依赖: <dependency>            <groupId>org.springframework</groupId& ...

  2. nginx auth

    location / { auth_basic "closed site";##Context:http, server, location, limit_except auth_ ...

  3. CMD和AMD区别的概括

    CMD和AMD区别   AMD CMD 关于依赖的模块 提前执行(不过 RequireJS 从 2.0 开始,也改成可以延迟执行(根据写法不同,处理方式不同)), 延迟执行 关于依赖的位置 依赖前置 ...

  4. BZOJ4519: [Cqoi2016]不同的最小割

    Description 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成 两个部分,如果结点s,t不在同一个部分中,则称这个划分是关于s,t的割.对于带权图来说,将 ...

  5. zoj Gao The Sequence

    Gao The Sequence Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given a sequence of integ ...

  6. 【web安全】第三弹:web攻防平台pentester安装及XSS部分答案解析

    web for pentester是国外安全研究者开发的的一款渗透测试平台,通过该平台你可以了解到常见的Web漏洞检测技术. 下载链接及文档说明: http://pentesterlab.com/ex ...

  7. Eclipse 中,web项目在Tomcat运行时填写不了Server name

    最近开发项目,从MyEclipse中导入项目到Eclipse中,那些WEB属性都在,可就是不能在Tomcat上运行.纠结一番,最后发现是这个问题: WEB的版本问题. 具体问题看下图: 解决方案: W ...

  8. 2016腾讯we大会的时间——2016年11月6日

    作为腾讯公司主办的一场国际化创新盛会,WE大会由腾讯公司自2013年以来每年举办,WE大会已迎来第四年,每年大会都会邀请全球互联网思想家.前沿创新团队来进行现场演讲和分享,分享最前沿的思想和技术,创造 ...

  9. (网页)jQueryAJAXtimeout超时问题详解(转)

    先给大家分析下超时原因: 1.网络不通畅. 2.后台运行比较慢(服务器第一次运行时,容易出现) 超时结果:JQ中 timeout设置请求超时时间. 如果服务器响应时间超过了 设置的时间,则进入 ERR ...

  10. Fourteenth scrum meeting

    闫昊 今日完成:整理上一阶段代码,规划第二阶段实施过程 明日完成:学习讨论区开发 唐彬 今日完成:整理上一阶段代码,规划第二阶段实施过程 明日完成:学习学习进度部分开发 史烨轩 今日完成:整理上一阶段 ...