Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT COUNT distinct

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
411
0
16
IT
SELECT CASSA.GIORNO, Count(CASSA.SCONTRINO) AS CONTASCONTRINO
FROM CASSA
WHERE CASSA.ANNULL IS NULL AND CASSA.ANNO='2021' AND CASSA.MESE='8'
GROUP BY CASSA.GIORNO

but i need to count distinct SCONTRINO

In my case the day 01/08/2021 have 11 SCONTRINO
 
 https://files.engineering.com/getfile.aspx?folder=545b274a-8b40-4769-961e-44df970837bb&file=OMBRELLONI.zip
Have you tried:
Code:
SELECT CASSA.GIORNO, Count(DISTINCT CASSA.SCONTRINO) AS CONTASCONTRINO
FROM CASSA
WHERE CASSA.ANNULL IS NULL AND CASSA.ANNO='2021' AND CASSA.MESE='8'
GROUP BY CASSA.GIORNO

If that doesn't work, you might try
Code:
SELECT giorno, count(scontrino) 
  FROM (SELECT DISTINCT giorno, scontrino 
          FROM cassa
         WHERE ANNULL IS NULL AND ANNO='2021' AND MESE='8') v;
 
TKS CARP, have you tested?
i'm on Access
 
No, I have not tested this. Since I didn't know what system you were on, it wouldn't have made much difference since I would have tested on Oracle.
But since it should be a simple copy/paste for you, it would be better if you tested it, no?
 
Sal21 - have you tested?
This works on Oracle, but Access may have different results.
 
Carp, with a little modify, and work, tks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top