1

I have a table called v_xml_cdr and have a the following columns: uuid, start_epoch and end_epoch. I want to be able to query the table for the start_epoch of of a uuid and then take that uuid and query the table again for all calls that have a start_epoch of less than or equal to the start_epoch from the previously found uuid and an end_epoch of greater than or equal to that same previously found start_epoch. Here is what I have so far, but it returns an empty result set. It should return 5 rows.

select count(uuid)
from v_xml_cdr
where start_epoch
      <= (select start_epoch as reject_start
          from v_xml_cdr
          where uuid = '5c076428-3790-11e7-868a-xxxxx'
         )
  and end_epoch
      >= (select start_epoch as reject_start
          from v_xml_cdr
          where uuid = '5c076428-3790-11e7-868a-xxxxx'
         );
3
  • 1
    Your query looks fine, except that you run the same subselect twice (maybe try WHERE (SELECT ...) BETWEEN start_epoch AND end_epoch). Can you provide sample data to prove that the query does not do what you want? Can you verify that the subselect returns a single row and not NULL? Commented May 14, 2017 at 4:33
  • Sample data and desired results would really help. Commented May 14, 2017 at 4:39
  • Thanks for your help. I am getting the following "ERROR: more than one row returned by a subquery used as an expression" Commented May 14, 2017 at 4:48

1 Answer 1

1

I think you want this:

select count(uuid)
from v_xml_cdr xc join
     (select min(start_epoch) as minse
      from v_xml_cdr xc1
      where uuid = '5c076428-3790-11e7-868a-xxxxx'
     ) xc1
     on xc.start_epoch <= xc1.minse and
        xc.end_epoch >= xc1.minse;
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Gordon, Thank you so much. This solved my problem. Just 1 further question, is there any way to only list if count(uuid) is greater than 5?
append to the query: having count(uuid) > 5
@user3896519 . . . I'm not sure what that means. This returns only one column and one row. What should it return if the count is not greater than 5?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.