I have following query which returns me of percentage of rows with at least one NULL in any of columns: Query works fine to me and I am getting valid result. But I need to do further action in tablec, based on percentage calculated in my SELECT statement. If percentage of rows with NULL is below 30% I need to
Tag: sql
Calculate rank based on Consecutive Dates (Return to 1 if there is a gap days between dates)
I am trying to get the rank column of this table. Key Date1 Name1 Location1 20 2021-12-30 Ann Site A 23 2021-12-31 Ann Site A 26 2022-01-03 Ann Site A 28 2022-01-04 Ann Site A 29 2022-01-05 Ann Site A 32 2022-01-06 Ann Site A 62 2022-01-08 Ann Site A 63 2022-01-10 Ann Site A 64 2022-01-11 Ann Site A
Joining and combining two tables that have the same ID for different rows
In SQLite I have two tables, tab_a and tab_b. Both have some similar columns and some that differ: So in this example both tables have the columns id, utc, name and three other columns that are specific to those respective tables. Moreover, the id field in both tables can contain the same values. However, the…
Is there a function/workaround to combining results from more than one table
I am using a dataset of a fictional bike sharing service. The data altogether emcompasses 12 months of data, split into 12 tables, one for each month. The columns and datatypes are consistent, and I am focusing on two columns – member-type and ride_length. The member_type column only has two values, …
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…
Is there a way to use IN and it evaluate values left to right in T-SQL?
Simplified example: I have been searching and cannot find a solid answer on this. I want to use the IN clause to get certain rows, but I want it to work left to right. In the example above, I would want a row for 2021, then 2015, then 2010 (assuming no seasons were null). Is there a way to make
SQL, extract everything before 5th comma
For example, my column “tags” have I’m trying to return everything before 5th comma. below is the result example I’ve tried below code but it’s not working. Answer You can use See the regex demo. The REGEXP_REPLACE will find the occurrence of the following pattern: ^ – star…
Ajax request from PHP don’t return me an Array
I’m trying to return an array from a PHP script in Ajax, however, it seems to not work, it returns me a string rather an Array. I’m using CodeIgniter Framework, there is my .php code : And there is my Ajax request : My getAll() function just select all from the database, however i’m only usi…
How to dynamically write OR clause in Contains query?
Is there a way to generate the second part of this SQL query (OR clauses) from a string split? String split values come from : Answer You can split the string using STRING_SPLIT(), then rebuild it using STRING_AGG(), and simply pass the resulting string into CONTAINS: Or even simpler: In both cases, @SearchPh…
Use one of two dates in where clause
I need to delete all records in a table where the CreatedDate or ModifiedDate is greater than x. The logic is as follows: If ModifiedDate is not null then use this value Otherwise use the CreatedDate value Not applying the if/else statement correctly. Answer Use this where clause: