Attualmente quando rilascio questo SQL, ottiene il nome utente distinto.Come raggruppare con una condizione speciale
Ho alcuni nomi utente distinti, che rappresentano gruppi, ad es. GRP_BSN
.
Vorrei raggruppare tutti gli altri nomi utente (che capita di essere numerici) in un gruppo, ad es. GRP_OTHERS
select username, count(*)
from host
where seq between 0 and 2000
group by username;
63149 1
63732 1
64110 2
70987 12
76841 4
GRP_BSN 226
GRP_ASN 243
GRP_DSC 93
Posso realizzare qualcosa di simile:
GRP_OTHERS 20
GRP_BSN 226
GRP_ASN 243
GRP_DSC 93
EDIT: Modificato query dalla risposta
select username, count(*)
from host
where created_dt
-- date selection
between to_date('2012-may-23 00:00:00', 'yyyy-mon-dd hh24:mi:ss')
and to_date('2012-may-23 23:59:59', 'yyyy-mon-dd hh24:mi:ss')
GROUP BY CASE
WHEN REGEXP_LIKE(username, '^\d+$') THEN 'GRP_OTHERS'
ELSE username
END;
mi chiedevo se avevamo 'GROUP bY (concate (COL1 E COL2))' –