0

I have this code I need to have row count off. I tried to count it but comes as Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

Can you help me with row count, thank you.

select count((
    select a.GIRIS_ZAMANI, a.CIKIS_ZAMANI, a.PLAKA, a.UCRET, b.KAMERA_ADI
    from ARAC_CIKIS a 
    left join KAMERALAR b 
    on b.KAMERA_ID = a.CIKIS_KAMERA_ID
    where a.CIKIS_ZAMANI between 
        (select cast(cast(sysutcdatetime() as date) as datetime) + cast('00:00:00' as datetime)) and 
        (select cast(cast(sysutcdatetime() as date) as datetime) + cast('23:59:59' as datetime)) and 
        a.UCRET>0
    )
)
3
  • 1
    Help us help you - please share some sample data and the result you're trying to get for it. Commented Apr 9, 2020 at 12:05
  • I got a list but just need row count from this chart Commented Apr 9, 2020 at 12:07
  • Does query work without count? I would recommend you test query without counting lines, only with some LIMIT clause at the end and the add SELECT COUNT(*) Commented Apr 9, 2020 at 12:15

2 Answers 2

1

You can try below -

select count(*)
from
(
select a.GIRIS_ZAMANI, a.CIKIS_ZAMANI, a.PLAKA, a.UCRET, b.KAMERA_ADI  from ARAC_CIKIS a left join KAMERALAR b on b.KAMERA_ID = a.CIKIS_KAMERA_ID
  where a.CIKIS_ZAMANI between cast(cast(sysutcdatetime() as date) as datetime) 
    + cast('00:00:00' as datetime) and cast(cast(sysutcdatetime() as date) as datetime) 
    + cast('23:59:59' as datetime)
 and  a.UCRET>0
) A
Sign up to request clarification or add additional context in comments.

Comments

0

Why are you using a subquery?

select count(*)
from ARAC_CIKIS a left join
     KAMERALAR k
     on bkKAMERA_ID = a.CIKIS_KAMERA_ID
where a.CIKIS_ZAMANI between cast(cast(sysutcdatetime() as date) as datetime) + cast('00:00:00' as datetime) and
                             cast(cast(sysutcdatetime() as date) as datetime) + cast('23:59:59' as datetime) and
      a.UCRET > 0

Comments

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.