根据条件更新值排名-Oracle

时间:2019-06-01 19:58:09

标签: sql oracle

我有一张桌子:

表1

<?php
    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        $userName = $user->user_login;
    }
?>
<script type="text/javascript">
    function _gaLt(event) {

        /* If GA is blocked or not loaded, or not main|middle|touch click then don't track */
        if (!ga.hasOwnProperty("loaded") || ga.loaded != true || (event.which != 1 && event.which != 2)) {
            return;
        }

        var el = event.srcElement || event.target;

        /* Loop up the DOM tree through parent elements if clicked element is not a link (eg: an image inside a link) */
        while (el && (typeof el.tagName == 'undefined' || el.tagName.toLowerCase() != 'a' || !el.href)) {
            el = el.parentNode;
        }

        /* if a link with valid href has been clicked */
        if (el && el.href) {

            var link = el.href;

            /* Only if it is an external link */
            if (link.indexOf(location.host) == -1 && !link.match(/^javascript\:/i)) {

                /* Is actual target set and not _(self|parent|top)? */
                var target = (el.target && !el.target.match(/^_(self|parent|top)$/i)) ? el.target : false;

                /* Assume a target if Ctrl|shift|meta-click */
                if (event.ctrlKey || event.shiftKey || event.metaKey || event.which == 2) {
                    target = "_blank";
                }

                var hbrun = false; // tracker has not yet run

                /* HitCallback to open link in same window after tracker */
                var hitBack = function() {
                    /* run once only */
                    if (hbrun) return;
                    hbrun = true;
                    window.location.href = link;
                };

                if (target) { /* If target opens a new window then just track */
                    ga(
                        "send", "event", "Outgoing Links", link,
                        document.location.pathname + document.location.search
                    );
                } else { /* Prevent standard click, track then open */
                    event.preventDefault ? event.preventDefault() : event.returnValue = !1;
                    /* send event with callback */
                    ga(
                        "send", "event", "Outgoing Links", link,
                        document.location.pathname + document.location.search, {
                            "hitCallback": hitBack
                        }
                    );

                    /* Run hitCallback again if GA takes longer than 1 second */
                    setTimeout(hitBack, 1000);
                }
            }
        }
    }

    var _w = window;
    /* Use "click" if touchscreen device, else "mousedown" */
    var _gaLtEvt = ("ontouchstart" in _w) ? "click" : "mousedown";
    /* Attach the event to all clicks in the document after page has loaded */
    _w.addEventListener ? _w.addEventListener("load", function() {document.body.addEventListener(_gaLtEvt, _gaLt, !1)}, !1)
        : _w.attachEvent && _w.attachEvent("onload", function() {document.body.attachEvent("on" + _gaLtEvt, _gaLt)});
</script>
<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-myUAID', 'auto');
    <?php if (isset($userName)) : ?>
        ga('set', 'userId', <?php echo(json_encode($userName)); ?>); // Set the user ID using signed-in user_id.
    <?php endif; ?>
    ga('send', 'pageview');
</script>

我需要为每个u_a_id e_id line_num column_name col_val my_seq 1 HI02-01 1 TestQ ABF 1 1 HI03-02 1 TestC 154 1 1 HI02-02 1 TestC 234 1 1 HI03-01 1 TestQ BF 1 1 HI04-02 1 TestC 151 1 1 HI04-01 1 TestQ BQ 1 2 HI02-01 1 TestQ ABF 1 2 HI03-02 1 TestC 154 1 2 HI02-02 1 TestC 234 1 2 HI03-01 1 TestQ BF 1 2 HI04-02 1 TestC 151 1 2 HI04-01 1 TestQ BQ 1 更新my_seq,仅当column_name相同时,才按u_a_idline_num和column_name排序。

输出为:

e_id

如何更新u_a_id e_id line_num column_name col_val my_seq 1 HI02-01 1 TestQ ABF 1 1 HI02-02 1 TestC 234 1 1 HI03-01 1 TestQ BF 2 1 HI03-02 1 TestC 154 2 1 HI04-01 1 TestQ BQ 3 1 HI04-02 1 TestC 151 3 2 HI02-01 1 TestQ ABF 1 2 HI02-02 1 TestC 234 1 2 HI03-01 1 TestQ BF 2 2 HI03-02 1 TestC 154 2 2 HI04-01 1 TestQ BQ 3 2 HI04-02 1 TestC 151 3

1 个答案:

答案 0 :(得分:0)

您可以使用g计算seq值:

DENSE_RANK

更新:

SELECT t.*, 
  DENSE_RANK() OVER(PARTITION BY u_a_id, column_name ORDER BY line_num, e_id) AS new_seq_id
FROM tab t;