• 10.3 定位连续值范围的开始点和结束点


    drop view v;
    create table v (
    proj_id int(2),
    proj_start date,
    proj_end date);

    insert into v values(1,'2005-03-01','2005-03-02');
    insert into v values(2,'2005-03-02','2005-03-03');
    insert into v values(3,'2005-03-03','2005-03-04');
    insert into v values(4,'2005-03-04','2005-03-05');
    insert into v values(5,'2005-03-05','2005-03-07');
    insert into v values(6,'2005-03-06','2005-03-17');
    insert into v values(7,'2005-03-17','2005-03-18');
    insert into v values(8,'2005-03-18','2005-03-19');
    insert into v values(9,'2005-03-19','2005-03-20');
    insert into v values(10,'2005-03-21','2005-03-22');
    insert into v values(11,'2005-03-26','2005-03-27');
    insert into v values(12,'2005-03-27','2005-03-28');
    insert into v values(13,'2005-03-28','2005-03-29');
    insert into v values(14,'2005-03-29','2005-03-30');

    create view v2
    as 
    select a.*,case when (
    select b.proj_id from v b
    where a.proj_start = b.proj_end
    )
    is not null then 0 else 1
    end as flag
    from v a;

    mysql> select * from v2;
    +---------+------------+------------+------+
    | proj_id | proj_start | proj_end   | flag |
    +---------+------------+------------+------+
    |       1 | 2005-03-01 | 2005-03-02 |    1 |
    |       2 | 2005-03-02 | 2005-03-03 |    0 |
    |       3 | 2005-03-03 | 2005-03-04 |    0 |
    |       4 | 2005-03-04 | 2005-03-05 |    0 |
    |       5 | 2005-03-05 | 2005-03-07 |    0 |
    |       6 | 2005-03-06 | 2005-03-17 |    1 |
    |       7 | 2005-03-17 | 2005-03-18 |    0 |
    |       8 | 2005-03-18 | 2005-03-19 |    0 |
    |       9 | 2005-03-19 | 2005-03-20 |    0 |
    |      10 | 2005-03-21 | 2005-03-22 |    1 |
    |      11 | 2005-03-26 | 2005-03-27 |    1 |
    |      12 | 2005-03-27 | 2005-03-28 |    0 |
    |      13 | 2005-03-28 | 2005-03-29 |    0 |
    |      14 | 2005-03-29 | 2005-03-30 |    0 |
    +---------+------------+------------+------+


    select a.proj_id,a.proj_start,a.proj_end,
    (select sum(b.flag)
    from v2 b 
    where b.proj_id <=a.proj_id ) as proj_prp
    from v2 a;

  • 相关阅读:
    自定义UINavigationBar
    UIImage 拉伸图片 resizableImageWithCapInsets
    自定义UINavigationBar上面的按钮
    tableView中deselectRowAtIndexPath的作用
    [LeetCode] Search a 2D Matrix, Solution
    [LeetCode] Longest Valid Parentheses, Solution
    我也写了一个牛顿迭代法,貌似不需要特殊处理溢出的情况 class Solution { public...
    [LeetCode] Remove Duplicates from Sorted List II, Solution
    [LeetCode] Palindrome Partitioning, Solution
    [LeetCode] Two Sum, Solution
  • 原文地址:https://www.cnblogs.com/l10n/p/7523329.html
Copyright © 2020-2023  润新知