如果是相同的日期值,如何从td中删除日期值?

时间:2016-04-18 12:30:27

标签: javascript jquery html sql

我有一个表格,其中每个表格行重复我的日期值。我试图用我的查询中的SQL解决这个问题但是那里不能做到所以我正在寻找其他解决方案用Javascript或JQuery来解决这个问题。所以我想删除日期值,如果它们重复,但如果日期值在我的td中改变,我会保留它。表格如下:

Date            Time
10/19/2016  8:00 AM - 8:30 AM       
10/19/2016  8:30 AM - 9:00 AM       
10/19/2016  9:00 AM - 9:30 AM       
10/19/2016  9:30 AM - 10:00 AM      
10/19/2016  10:00 AM - 10:30 AM         
10/19/2016  10:30 AM - 11:00 AM         
10/19/2016  11:00 AM - 11:30 AM         
10/19/2016  11:30 AM - 12:00 PM         
10/19/2016  12:00 PM - 12:30 PM         
10/19/2016  12:30 PM - 1:00 PM      
10/19/2016  1:00 PM - 1:30 PM       
10/19/2016  1:30 PM - 2:00 PM       
10/20/2016  9:00 AM - 9:20 AM       
10/20/2016  9:20 AM - 9:40 AM       
10/20/2016  9:40 AM - 10:00 AM      
10/20/2016  10:00 AM - 10:20 AM         
10/20/2016  10:20 AM - 10:40 AM         
10/20/2016  10:40 AM - 11:00 AM         
10/20/2016  11:00 AM - 11:20 AM         
10/20/2016  11:20 AM - 11:40 AM         
10/20/2016  11:40 AM - 12:00 PM         
10/20/2016  12:00 PM - 12:20 PM         
10/20/2016  12:20 PM - 12:40 PM         
10/20/2016  12:40 PM - 1:00 PM      
10/20/2016  1:00 PM - 1:20 PM       
10/20/2016  1:20 PM - 1:40 PM       
10/20/2016  1:40 PM - 2:00 PM       
10/20/2016  2:00 PM - 2:20 PM       
10/20/2016  2:20 PM - 2:40 PM 

正如您在上面所看到的,这与每行列出的所有日期非常混淆,我想保留每个日期的第一个日期值。像这样:

Date            Time
10/19/2016  8:00 AM - 8:30 AM       
            8:30 AM - 9:00 AM       
            9:00 AM - 9:30 AM       
            9:30 AM - 10:00 AM      
            10:00 AM - 10:30 AM         
            10:30 AM - 11:00 AM         
            11:00 AM - 11:30 AM         
            11:30 AM - 12:00 PM             
            12:00 PM - 12:30 PM         
            12:30 PM - 1:00 PM      
            1:00 PM - 1:30 PM       
            1:30 PM - 2:00 PM       
10/20/2016  9:00 AM - 9:20 AM       
            9:20 AM - 9:40 AM       
            9:40 AM - 10:00 AM      
            10:00 AM - 10:20 AM         
            10:20 AM - 10:40 AM         
            10:40 AM - 11:00 AM         
            11:00 AM - 11:20 AM         
            11:20 AM - 11:40 AM         
            11:40 AM - 12:00 PM         
            12:00 PM - 12:20 PM         
            12:20 PM - 12:40 PM         
            12:40 PM - 1:00 PM      
            1:00 PM - 1:20 PM       
            1:20 PM - 1:40 PM       
            1:40 PM - 2:00 PM       
            2:00 PM - 2:20 PM       
            2:20 PM - 2:40 PM

以下是我目前用于向屏幕输出值的代码:

<table>
        <thead>
            <tr>
                <th>Date</th>
                <th>Time Slots</th>
            </tr>
        </thead>
        <tbody>
            ~[tlist_sql;
                Select to_char(PTC_DATE,'mm/dd/yyyy'),SLOT_LABEL
                From EVENT_SLOTS 
                Where e.EVENT_ID = '145'
                Order by PTC_DATE, DISPLAY_ORDER;]
            <tr>
                <td>~(PTC_DATE)</td>
                <td>~(SLOT_LABEL)</td>
            </tr>
            [/tlist_sql]
        </tbody>
    </table>

如果甚至可以删除Date td标记中的重复日期值,会怎样?如果有人可以提供帮助,请告诉我。感谢。

2 个答案:

答案 0 :(得分:1)

好的,如果你真的想在jquery / javascript中为每个日期<td>标记添加类,并运行此代码:

    var placeholder = '';
$(".date").each(function() {
  if (placeholder != '') {
    if (placeholder == $(this).text()) {
      $(this).text("");
    } else {
      placeholder = $(this).text();
    }
  } else {
    placeholder = $(this).text();
  }
});

https://jsfiddle.net/j4v387nu/

答案 1 :(得分:0)

您可以使用类似于以下内容的空白更新日期值:

  update table1 a 
  set a.date ='' 
  where a.time > (
                   select min(time) 
                   from table1 
                   where date=a.date
                  )

使用增量列进行过滤将完成工作

   update table1 a 
   set a.date ='' 
   where a.ID > (
               select min(ID) 
               from table1 
               where a.date=date

              )