0

这听起来可能有点无聊,但我正在尝试计算查询中返回的总行数。我试过 COUNT() 无济于事。到目前为止,我有这个查询:

SELECT DISTINCT
    a.*  
    , LEVEL AS n
    , count(wipdatavalue) as total
FROM
(
  SELECT
    WIPDATAVALUE
    , CONTAINERNAME
    , una
    , dulo
    , (dulo - una) + 1 AS m
  FROM
  (
    SELECT 
      WIPDATAVALUE
      , CONTAINERNAME
      , CASE
          WHEN INSTR(wipdatavalue, '-') = 0 THEN
            wipdatavalue
          ELSE
            SUBSTR(wipdatavalue, 1, INSTR(wipdatavalue, '-')-1) 
         END AS una
      , CASE
          WHEN INSTR(wipdatavalue, '-') = 0 THEN
            wipdatavalue
          ELSE
            SUBSTR(wipdatavalue, INSTR(wipdatavalue, '-') + 1)
         END AS dulo
    FROM trprinting
    WHERE containername = '8PB842613'
  )
)A CONNECT BY LEVEL <= m
GROUP BY
  WIPDATAVALUE
    , CONTAINERNAME
    , una
    , dulo
    , m
    , LEVEL
ORDER BY N;

在此处输入图像描述

我也在尝试将 N 字段设置为 1 到 8,因为这应该是正确的输出。提前致谢。我知道你们会有所帮助:)

4

1 回答 1

0

你想做这样的事情:

with data (wipdatavalue, containername, una, dulo, m, n)
     as (select wipdatavalue,containername,una,dulo,( dulo - una ) + 1 as m,una n
           from (select wipdatavalue,containername,
                        case
                          when Instr(wipdatavalue, '-') = 0
                          then
                            to_number(wipdatavalue)
                          else
                            to_number(Substr(wipdatavalue, 1, Instr(wipdatavalue, '-') - 1))
                          end as una,
                          case
                            when Instr(wipdatavalue, '-') = 0 
                            then
                              to_number(wipdatavalue)
                            else
                              to_number(Substr(wipdatavalue, Instr(wipdatavalue, '-') + 1))
                          end as dulo
                   from trprinting
                  where containername = '8PB842613')
         union all
         select wipdatavalue,containername,una,dulo,m,n + 1
           from data
          where n + 1 <= dulo)
select wipdatavalue,containername,una,dulo,m,n,
       count(*) over () total_rows
  from data
 order by wipdatavalue,n; 

小提琴:http ://sqlfiddle.com/#!4/11082/2

于 2013-03-05T08:14:34.933 回答