<i id='xSFao'><tr id='xSFao'><dt id='xSFao'><q id='xSFao'><span id='xSFao'><b id='xSFao'><form id='xSFao'><ins id='xSFao'></ins><ul id='xSFao'></ul><sub id='xSFao'></sub></form><legend id='xSFao'></legend><bdo id='xSFao'><pre id='xSFao'><center id='xSFao'></center></pre></bdo></b><th id='xSFao'></th></span></q></dt></tr></i><div id='xSFao'><tfoot id='xSFao'></tfoot><dl id='xSFao'><fieldset id='xSFao'></fieldset></dl></div>

    <legend id='xSFao'><style id='xSFao'><dir id='xSFao'><q id='xSFao'></q></dir></style></legend>
      <bdo id='xSFao'></bdo><ul id='xSFao'></ul>
  1. <small id='xSFao'></small><noframes id='xSFao'>

  2. <tfoot id='xSFao'></tfoot>
    1. MySQL - 基于 SELECT 查询的 UPDATE 查询

      时间:2023-08-20
        1. <tfoot id='4NjMx'></tfoot>
          <i id='4NjMx'><tr id='4NjMx'><dt id='4NjMx'><q id='4NjMx'><span id='4NjMx'><b id='4NjMx'><form id='4NjMx'><ins id='4NjMx'></ins><ul id='4NjMx'></ul><sub id='4NjMx'></sub></form><legend id='4NjMx'></legend><bdo id='4NjMx'><pre id='4NjMx'><center id='4NjMx'></center></pre></bdo></b><th id='4NjMx'></th></span></q></dt></tr></i><div id='4NjMx'><tfoot id='4NjMx'></tfoot><dl id='4NjMx'><fieldset id='4NjMx'></fieldset></dl></div>
          <legend id='4NjMx'><style id='4NjMx'><dir id='4NjMx'><q id='4NjMx'></q></dir></style></legend>
            <tbody id='4NjMx'></tbody>

            <small id='4NjMx'></small><noframes id='4NjMx'>

              <bdo id='4NjMx'></bdo><ul id='4NjMx'></ul>
              1. 本文介绍了MySQL - 基于 SELECT 查询的 UPDATE 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我需要检查(从同一张表中)基于日期-时间的两个事件之间是否存在关联.

                I need to check (from the same table) if there is an association between two events based on date-time.

                一组数据将包含某些事件的结束日期时间,另一组数据将包含其他事件的开始日期时间.

                One set of data will contain the ending date-time of certain events and the other set of data will contain the starting date-time for other events.

                如果第一个事件在第二个事件之前完成,那么我想将它们链接起来.

                If the first event completes before the second event then I would like to link them up.

                到目前为止我所拥有的是:

                What I have so far is:

                SELECT name as name_A, date-time as end_DTS, id as id_A 
                FROM tableA WHERE criteria = 1
                
                
                SELECT name as name_B, date-time as start_DTS, id as id_B 
                FROM tableA WHERE criteria = 2
                

                然后我加入他们:

                SELECT name_A, name_B, id_A, id_B, 
                if(start_DTS > end_DTS,'VALID','') as validation_check
                FROM tableA
                LEFT JOIN tableB ON name_A = name_B
                

                然后,我可以根据我的validation_check 字段运行带有 SELECT 嵌套的 UPDATE 查询吗?

                Can I then, based on my validation_check field, run a UPDATE query with the SELECT nested?

                推荐答案

                您实际上可以通过以下两种方式之一执行此操作:

                You can actually do this one of two ways:

                MySQL 更新连接语法:

                MySQL update join syntax:

                UPDATE tableA a
                INNER JOIN tableB b ON a.name_a = b.name_b
                SET validation_check = if(start_dts > end_dts, 'VALID', '')
                -- where clause can go here
                

                ANSI SQL 语法:

                ANSI SQL syntax:

                UPDATE tableA SET validation_check = 
                    (SELECT if(start_DTS > end_DTS, 'VALID', '') AS validation_check
                        FROM tableA
                        INNER JOIN tableB ON name_A = name_B
                        WHERE id_A = tableA.id_A)
                

                选择你认为最自然的那个.

                Pick whichever one seems most natural to you.

                这篇关于MySQL - 基于 SELECT 查询的 UPDATE 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在 MySQL 中查找重复记录 下一篇:如何将整个 MySQL 数据库字符集和排序规则转换为

                相关文章

                最新文章

              2. <small id='w2jUj'></small><noframes id='w2jUj'>

                  <bdo id='w2jUj'></bdo><ul id='w2jUj'></ul>
                <tfoot id='w2jUj'></tfoot>
              3. <legend id='w2jUj'><style id='w2jUj'><dir id='w2jUj'><q id='w2jUj'></q></dir></style></legend>

                <i id='w2jUj'><tr id='w2jUj'><dt id='w2jUj'><q id='w2jUj'><span id='w2jUj'><b id='w2jUj'><form id='w2jUj'><ins id='w2jUj'></ins><ul id='w2jUj'></ul><sub id='w2jUj'></sub></form><legend id='w2jUj'></legend><bdo id='w2jUj'><pre id='w2jUj'><center id='w2jUj'></center></pre></bdo></b><th id='w2jUj'></th></span></q></dt></tr></i><div id='w2jUj'><tfoot id='w2jUj'></tfoot><dl id='w2jUj'><fieldset id='w2jUj'></fieldset></dl></div>