Skip to content

Tag: mysql

Reuse select aliases in MySQL

I currently have a query where I’m doing two subqueries to get X, Y data: Y is kind of subset of X, since I apply just an additional condition to the existing ones, if X is: Then Y has an additional AND condition: And for the value of X I need to take those two results – X and Y

Count of values grouped by a row id

My data looks like the below, I want to sum up the count of occurrences of ALL. This should be grouped by Id. So the output should look like, My query looks like, This query is giving me the result as, which is incorrect for Id 2. The value for Friday for the second row is an empty string. dbfiddle