First post here… I’m trying to create select values from tableA in last 5 minutes and to compare those values each row by row with average(value) from another table. For example: tableA id | …
Tag: select
SQL concat case select when trying to add new column of previous month data
I have a data set in which I need to concat month and year for the previous month. the problem is it spans over two years. I need to create a statement in which mean the month – 1 = 0, month becomes …
SQL Window Function – Number of Rows since last Max
I am trying to create a SQL query that will pull the number of rows since the last maximum value within a windows function over the last 5 rows. In the example below it would return 2 for row 8. The …
Select data that wont expire in the next 60 days
I’m trying to select data that won’t expire in the next 60 days so far I have this $sql = “SELECT id FROM cooler WHERE expiry_date > CURDATE()”; which only shows data that has not expire.
SQL: Nested Select vs Double JOIN by Performance
I have report based on a stored procedures and I need to add User name into output. In my system TWO users can be owners of transaction. Also, in my system User information stored in different …
My Left Join Query in mySql gives duplicate results even after using DISTINCT?
I have tried many solutions to get rid of Duplicate results in Query but no use. Here are my tables: sparepartorderdetails d table: id —– SparePartID ——–OrderID ——– Qty —– Price 101-…
SQL Server : “invalid column name” error after GROUP BY on subquery
I am trying to perform the following query on a SQL Server database table with a GROUP BY on a column which results from a CASE statement done on a subquery: SELECT AVG(sales) as avg_sales, …
PHP and Mysql, avoid multiple loop queries
I have a table myTable that looks like this: +——-+——-+——–+————+ | Id | Agent | Qualif | Date | +——-+——-+——–+————+ | 1 | A | Q1 | 2019-05-…
How to select only rows from a table one clumns value is more than b table count value in MySQL
Table A: id, name, school_code ——————- 1,David,10601 2,Jack,10602 3,John,10603 4,Hank,10602 5,Daisy,10601 6,Kelly,10602 7,May,10602 8,Mayme,10602 Table B: id, school_code,max_stu ——-…
How to Create SELECT for Total sales for each region
I want to write a query to get Total sales for every region, but i cant figure the way to do it. I have these tables: Region(RegionID, Name) Client(ClientID, Name, City, Country, Email, RegionID) …