Mysql的数据查询语句(项目记录)

SELECT
    i.policy_no  as 保单号,
    i.create_time as 创建时间,
    n.operate_time as 提交时间
FROM
    op_endor_info i,
    op_endor_node_detail n
WHERE
    i.policy_no = n.policy_no
AND n.result = '通过' and i.endor_no = n.endor_no;


-- 查询事件录入
    

UNION
-- 新建事件和领取
SELECT
    i.create_time AS 创建时间,
    n.operate_time AS 操作时间,
    avg(n.operate_time - i.create_time) 时间差
FROM
    op_endor_info i
LEFT JOIN op_endor_node_detail n ON i.policy_no = n.policy_no
where n.operation_detail='领取' and i.endor_no = n.endor_no;

UNION

SELECT
    i.create_time AS 创建时间,
    n.operate_time AS 操作时间,
FROM
    op_endor_info i
LEFT JOIN op_endor_node_detail n ON i.policy_no = n.policy_no
where n.result='通过' and i.endor_no = n.endor_no;


SELECT * FROM op_endor_node_detail;

SELECT operate_time  FROM op_endor_node_detail where operation_detail = '提交' AND endor_no='2019061000015';2019-06-10 14:12:24
SELECT operate_time  FROM op_endor_node_detail where operation_detail = '领取' AND endor_no='2019061000015';2019-06-10 14:15:03

SELECT * FROM op_endor_node_detail where result = '通过'; 

select * from op_endor_info


SELECT
    t.policy_no AS 保单号,
    t.operation_detail AS 操作步骤,
    o.create_time AS 创建时间,
    t.operate_time AS 结束时间,
    t.result as 事件状态,
    SECOND(t.operate_time) - SECOND(o.create_time) AS 时间差
FROM
    op_endor_node_detail t,
    op_endor_info o
WHERE
    t.policy_no = o.policy_no
AND t.endor_no = o.endor_no
-- AND t.result = '通过'
AND t.policy_no ='600000510132018060120193888054';
UNION
SELECT
    t.policy_no AS 保单号,
    t.operation_detail AS 操作步骤,
    o.create_time AS 创建时间,
    t.operate_time AS 结束时间,
    t.result as 事件状态,
    SECOND(t.operate_time) - SECOND(o.create_time) AS 时间差
FROM
    op_endor_node_detail t,
    op_endor_info o
WHERE
    t.policy_no = o.policy_no
AND t.endor_no = o.endor_no
AND t.result = '通过'
AND t.policy_no is not null;

--查询某一天的数据:
SELECT * FROM op_endor_info where platform_source='min-b' and system_source is null and DATE_FORMAT(create_time,'%Y-%m-%d') = '2019-06-18';

-- 查询当天的数据
SELECT * FROM op_endor_info where DATEDIFF(create_time,NOW())= 0;
-- 查询一天的 同上
SELECT * FROM op_endor_info where TO_DAYS(create_time) = TO_DAYS(NOW());
SELECT * FROM op_endor_info where DATE(create_time) = CURDATE();

-- 查询昨天的数据
SELECT * FROM op_endor_info where TO_DAYS(NOW())- TO_DAYS(create_time) =1;

--7天
SELECT * FROM op_endor_info where DATE_SUB(CURDATE(),INTERVAL 7 DAY) < DATE(create_time);

-- 本月
SELECT * FROM op_endor_info where DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m');


--获取今天是一周的第几天或者周几  返回值 0是周一 6是周日
SELECT WEEKDAY(NOW());

时间戳转日期:
SELECT FROM_UNIXTIME(1560912691);
SELECT FROM_UNIXTIME(1560912691,'%Y-%m-%d')

日期转时间戳: --1560912691
SELECT UNIX_TIMESTAMP(NOW());


-- 查询每天数据汇总
SELECT
    DATE_FORMAT(create_time, '%Y-%m-%d') AS PerDay,
    count(0) AS Total
FROM
    op_endor_info
WHERE
    create_time BETWEEN '2019-06-01 00:00:00'
AND '2019-06-30 23:59:59'
GROUP BY
    PerDay
ORDER BY
    create_time;
    
或者是:
-- 查询每天的数据
SELECT
    COUNT(0) AS total
FROM
    op_endor_info
GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d')
;
    
-- 如何查询某个时间点 
DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s')


UPDATE
op_endor_info
SET 
platform_source =
CASE
    WHEN platform_source = 'APP-泰康在线' THEN    'APP'
    WHEN platform_source = '微信-泰康在线保险服务' THEN    'Healthy'
    WHEN platform_source = '支付宝-生活号' THEN    'ALIPAY'
    WHEN platform_source = '微信-泰康在线保险' THEN    'WeChatSelfHelp'
END
where creater_name = '三端一微';


 

你可能感兴趣的:(Java)