Skip to content

Tag: mysql

mysql: Select Max value and delete other rows

I need to get the row with the maximum status value for each employee_id and keep only one record for employee_id If status is equal for the same employee id then pick one and delete the other, Thank you and appreciated Table: ID Type Status emplyee_ID 1111 A 0 10 2222 A 1 10 3333 B 0 20 4444 B

List which has no reports submitted

I have two tables in MySQL database. tbl_sites (similarly around 3500 sites) tbl_reports (Similarly multiple reports from each sites) I want to get the list of sites by site name, where the report count is still zero. A report is considered as successfully submitted when the report_status = 2. Answer Using ex…

SQL UPDATE base on COUNT

I have two tables product-table with fields (id, category_id) category-table with fields (id, num_of_products) The product table contains multiple products in different categories. And I know how to count product in each categories using But how do I update category.num_of_product using a single sql query wit…

Interpolate Multiseries Data In SQL

I have a system that stores the data only when they are changed. So, the dataset looks like below. data_type_id data_value inserted_at 2 240 2022-01-19 17:20:52 1 30 2022-01-19 17:20:47 2 239 2022-01-19 17:20:42 1 29 2022-01-19 17:20:42 My data frequency is every 5 seconds. So, whether there’s any times…