MySQL Query with count and group by

Assuming that your date is an actual datetime column: SELECT MONTH(date), YEAR(date), id_publisher, COUNT(*) FROM raw_occurrence_record GROUP BY MONTH(date), YEAR(date), id_publisher You can concatenate your month & year like so: SELECT CONCAT(MONTH(date), “https://stackoverflow.com/”, YEAR(date)) AS Month, id_publisher, COUNT(*) FROM raw_occurrence_record GROUP BY MONTH(date), YEAR(date), id_publisher To find months where there are no records, you will … Read more

How to sort by count with postgresql?

You’ve aliased the table and column as the same thing, so don’t do that. It’s not invalid, just tough to follow. Anyway, include all columns that you’re selecting that aren’t aggregates in your group by: select count(w.id) as mycount, w.company_id, c.company_name, c.city from companies c left join workers w on c.id=w.company_id group by w.company_id, c.company_name, … Read more

jq count the number of items in json by a specific key

Here’s one solution (assuming the input is a stream of valid JSON objects) and that you invoke jq with the -s option: map({ItemId: .Properties.ItmId}) # extract the ItmID values | group_by(.ItemId) # group by “ItemId” | map({ItemId: .[0].ItemId, Count: length}) # store the counts | .[] # convert to a stream A slightly more memory-efficient … Read more

COUNT(id) vs. COUNT(*) in MySQL

I know this question is about MySQL, but for what it’s worth, count(*) is recommended for Oracle, which goes to show that the answer to this can be database dependent (see comment above from BalusC). Since a lot of databases (MS-SQL, MySQL) have information schema tables that hold various types of metadata, there are bound … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)