:startDate and :endDate are given value from html input and passed as parameters with AJAX. I want to return notifications BETWEEN :startDate and :endDate, but also return a notification if startDate …
Getting SUM of ‘x’ consecutive values where x is an integer from another row
I am trying to code in Microsoft SQL Server Management Studio. This is SQL. I have to get the sum of x previous consecutive rows where x is based on a number in another row. For Example: Example 1: …
Search function on multiple rows in the same table
I’m wondering how do I add more row’s on my search script to be searched. Here’s my php script: As you can see this: I want to it to search on region and rank rows. I tried: …. it’s showing 0 results. Thank you in advance. Answer Is this what you want? This searches for the param…
Update column value based on ORDER of another query
What I have: Hi guys, I have two tables. #1 model Where I store all models #2 video_models_model which connect model and video table (video is unrelated now) until now always when I needed models I ordered them based on in how many videos they are used in What I need: However I found out that sometimes I need…
How to replace table1 column value with table2 column value in MySQL select left join
Let’s say I have two MySQL tables: table1 (templates) Columns: id_template, name, col3, col4, … table2 (aliases) Columns: id_alias, id_template_orig, id_user, alias I want to select a row from the table1 (templates) including all the columns (*). In the same select statement I want to check if cur…
Dynamically Insert into Table A Based on Row_Num from Table B
I’ve condensed some data into TableB which looks like the following: There are 2000 unique rows in total, Row_Num from 1 to 2000, and every AreaID in this table is naturally unique as well. I now want to insert into a blank table, TableA, which has the following columns: The insert statement I want to u…
COUNT WHERE two conditions are met in the same column
I’m sure this has been asked before, but I can’t find a similar situation: Given a table ‘activity’ I need to count all users that have ‘SEM’ AND at least another channel IN contact_channel_ID Answer You can use aggregation and having: In MySQL, the having clause can be sho…
Insert a NEW Row using a Single Value from LAST row with Stored Procedure
Please refer to the screen captures below. I am trying to create a stored procedure in SQL Server 2014 that does the following: Sets the “Complete” BIT in the LAST record (e.g. row #1062) to TRUE Takes a the “DateTo” value from the LAST record (highlighted in yellow) and INSERTS it int…
For each ID get the first record where Product is not null (Postgresql)
I have customer data with information when the appointment took place, what type of appointment it was and wheather a Product was selected. I am trying to get the earliest appointment for every id where Product is not null. Basically reduce the table where id only appears once with appointment date and type w…
Find columns that have all values in another table
I’m having trouble with the query below. The aim is to select the clientID’s that have a loan in all of the branches in the city ‘Sherbrooke’. WITH sherb AS (SELECT branch_id FROM …