October 21, 2024
Chicago 12, Melborne City, USA

SQL

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample dat

SQL

How to Parse and Display CIBIL Payment History in Bold BI from JSON

I am trying to parse a JSON response from a CIBIL report and display the paymentHistory field in Bold BI as a tabular visualisation. The goal is to show the "Days Past Due/Asset Classification" over a 36-month period (left to right). Below is an example of the format I want to achieve: DAYS PAST DUE:

Read More
SQL

Is this SQL clause meaningless?

I ran across something strange in the SQLite "SqlLogicTest" test suite: WHERE (e>c OR e<d) AND d>e The e<d and d>e parts are exactly equivalent to one another, so this could be rewritten as WHERE (e>c OR d>e) AND d>e. And since the right half of that OR clause is now guaranteed to be true

Read More
SQL

Delete customer records during merge process but save primary record with flag as Y in other table

I have a weird situation where I have one primary table where there is no flag to identify or mark the records for deletion, so I have to rely on the rowid. The table A looks like Customer_No IdentityCode IdentityNumber 1234 passport ABCDEFGH 1234 passport ABCDEFGH 1234 adhar 1234 5678 9123 5678 passport ABCDEFGH Now

Read More
SQL

Update Set for a column

This is a sample table and I would like to update the column ‘TYPE’ as like the value which is there ‘STOCKIN’ /’STOCKOUT’ for the particular DOCNUM in each row. Sample Table CODE DOCNUM TYPE Z01 NUM12 stockin Z01 NUM12 null Z01 NUM12 null Z01 NUM12 null Z01 NUM134 stockout Z01 NUM134 null Z01 NUM134

Read More
SQL

How to fetch parent data and all it's children, then aggregate to array?

Postgres: v12 Link to test: https://www.db-fiddle.com/f/pfnFVhFq1QTxjas6BB4sZv/0 There are transactions table and logs table. logs are linked to transactions by transaction_id. I need to query logs by address, join it with transactions, aggregate logs to array, LIMIT transactions (example is LIMIT 2) and FETCH ALL LOGS that were in that transaction (but query only by one

Read More
SQL

Sqlite union with non existing table

I have an application where tables are dynamically created, while reading data we Union All the data from various tables and show the results, but issue comes when a table is not existing.. Is there a better way to write this query so that it doesnt fail when a table doesnt exists.. SELECT * FROM

Read More
SQL

How to achieve MySQL transaction with complicated computation?

For example, here’s a table with 2 columns called USER_ID, MY_COLUMN. I want to change the MY_COLUMN for a single user specified by USER_ID. If the modification is very naive/simple, say MY_COLUMN is an integer and we only want to increment it by 1, we can achieve this by a simple UPDATE ... SET ...

Read More
SQL

Use init SQL script in C# WPF apps

I’ve got a WPF application and i want to apply some init sql script in order to full some table. In my all project solution i’ve got one project for the application and one SQLProject to make compare when i modify the tables. i’ve put my sql script in the SQLProject folder, but how can

Read More
SQL

Rows matching conditions in a directly related table or another, related indirectly

Suppose three tables: create table table_a( id int generated by default as identity primary key); create table table_c( id int generated by default as identity primary key , active boolean); create table table_b( id int generated by default as identity primary key , active boolean , table_a_id int references table_a(id) , table_c_id int references table_c(id));

Read More
SQL

Using SQL in an Excel workbooks exhibits strange behaviour until the device is rebooted

I have a macro that runs a a number of different SQL statements. I use the same macro each day. The 1st step is I update the Pending worksheet. The 2nd step is to identify new contracts. New contracts are identified by a SQL statement that compares the Pending worksheet to the History worksheet. Anything

Read More