Categories
IT-HOWTO

MySQL get column name + concat

How to select columns from table + concat it to single line string

SELECT GROUP_CONCAT(COLUMN_NAME SEPARATOR ',')
FROM
( SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'rd_covic19' AND TABLE_NAME = 'tb_user_by_eoffice'
) a

Count people who active today

SELECT lsk 
FROM logs
WHERE
  SUBSTR(dt,1,10)=CURRENT_DATE
  AND LENGTH(lsk) > 0
GROUP BY lsk
ORDER BY lsk ;
SELECT COUNT(*) 
FROM (
  SELECT lsk 
  FROM logs
  WHERE
    SUBSTR(dt,1,10)=CURRENT_DATE
    AND LENGTH(lsk) > 0
  GROUP BY lsk
) a;