skip to Main Content
SELECT COUNT(*), 
tanggal as totRits AND COUNT(*), 
total AS tNote  
FROM tblsolar 
WHERE tanggal LIKE '%" & sqlDate & "%' 
AND supir LIKE '%" & cboSupir & "%' 
GROUP BY tanggal

How do I SELECT the COUNT two times?

2

Answers


  1. This COUNT function is used to find the number of indexes as returned from the query selected.

    Please see the below example-

    SELECT COUNT(Column1), COUNT(Column2) FROM Table;
    
    Login or Signup to reply.
  2. If you want to get the total COUNT and a COUNT of a specific column using different conditions, you can use a subquery like this:

    SELECT 
      (SELECT 
       COUNT(tanggal) AS totRits
       FROM tblsolar 
       WHERE tanggal LIKE '%sqlDate%' 
       AND supir LIKE '%cboSupir%' 
       GROUP By tanggal) AS totRits,
    COUNT(*) AS tNote
    FROM tblsolar
    

    Input:

    tanggal supir
    sqlDate cboSupir
    test test
    test cboSupir
    test cboSupir
    sqlDate cboSupir

    Output:

    totRits tNote
    2 5

    Adjust your WHERE clause conditions as needed for both the main query and subquery.

    db<>fiddle here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search