Skip to content
Advertisement

Tag: count

How to get common value based on a column from a table sql

I have a table. the screenshot is given bellow: There have two columns item_details_id pay_method_id In item_details_id there have 1,2,1 data. On the other hand pay_method_id have 1,1,3 data. I want to get only common values of pay_method_id depending on item_details_id. According to the given screenshot- in item_details_id I have ‘1’ & ‘2’ value. —– ‘1’ pay_method_id is ‘1’, ‘3’

I need to optimize this MYSQL query

I have tried NOT EXIST but didn’t get expected result can’t do index since duplicate entries of student_id,status are valid entries,Need to reduce execution time since the table has large number of data. Answer You can try query with JOIN condition: Here the fiddle SQLize.online Sure that your tables have index on student_id field. Since you filter by status field,

Get yearly average of per id

This code gets the number of ids that that show up for each month with in the year. This is the result i get: I want to get the yearly average of each ID, and the overall count. The results will look like this: Answer You can add another level of aggregation: Notes: you don’t actually need a CTE to

Advertisement