The avg salary of peers expects the employee itself(that is, for each employee its peer would be everyone in the same department as the employee but excluding the employee himself). We have two …
Tag: mysql
How to access a table using a variable name in sql query
I have multiple tables in my database named teacher1, teacher2…. I am trying to access them using a variable $id. I have written down the following code. $query = “SELECT * FROM table.$id”; How …
sql query to select records from mysql
Can suggest me the best way to select records from MySQL customer ——– id bed_id status 1 1 vocated 2 1 booked 3 2 vocated bed —– id name 1 lower 2 middle …
SELECT subCategory which equals parentCategory = value from outer table
I have a products table and I need to put discount on some products from a given sub category, which has parent category in another table. TABLE products: category_id sku discount —-…
MySQL: Select only if field values are ascending
I have two tables: Route and Stop (one to many). And also I have input data: two location IDs which is related to ‘stop’ table. Every route has it’s own ORDERED list of stops. I need to select Route …
How to Group By some id and Sum all row json encode data
I have Faced group by some id and Sum other column json_encode data in select query MySQL. But how to sum total json data value? Please help Anyone… Using this, PHP 7.2, Mysql 5 and Apache 2. …
Adding percentage to number in SQL
I would like to add a percentage sign after a number in SQL. This is the query I have select cast(vetted as float)/cast(account_create as float)*100 from numbers I have tried using the format …
SQL+Fetch rows with latest date+Case when row_number()+Duplicates
I have a table with fields(id, date, product) with below sample data id date Product current_Flag Expected_flag 14834 2019-01-03 00:00:00 A 1 1 14834 2019-01-31 00:00:00 B 0 0 …
Struggling with correlated subqueries in SQL
I have a database about old cars, their owners, events and the attendants of those events as such: Image of tables used : PK: Primary Key FK: Foreign Key Now I need to get the amount of different …
Select a conversation between exact users (by users IDs)
I’m woking on a simple chat app. It should allow users to run conversations user-to-user or in groups (multiple users). So here are my tables: table users ID | username | … table …