Skip to content

Tag: sql

Postgres SQL attribution over time range

I’m using Postgres 11 and trying to figure out if I can do this in a single query. Suppose I have two tables: When I join these tables by uuid, Event2 rows should be attributed to a particular Event1.id up to when a newer Event1.id is active. For example, if I have these rows: Event1: Event2: I would ge…

SQLGroup with Distinct count

I have query Outcome Not sure why not group by range and expect results. Thank you. Answer I would suggest cross apply to define the alias: SQL Server doesn’t allow aliases as GROUP BY keys. I think defining the alias in the FROM clause is the simplest method; you could also use a CTE or subquery or rep…

Combining 2 Tables in SQL and add a new column to a Table

I have 2 Tables. CustomerDetails table has columns ID, UUID, Name, Age. FavoriteCustomers table has columns ID, UUID CustomerDetails Table will have a lot of entries say 10000 rows. while FavoriteCustomers Table has very few entries. In CustomerDetails Table, ID and UUID form the combined unique ID. Now I wan…

Create XML from SQL select query

I am trying to create a xml from a SQL select, but I can not insert “:” (like cac:PartyTaxScheme), neither can put 2 data in one element, look element “cbc:CompanyID” (<cbc:CompanyID schemeName=”31″ schemeID=”0″ schemeAgencyID=”195″>900711000&l…

How Can My sqllite3 interaction be fixed?

I’m trying to get an admin account to edit a ‘rank’ (basically access level) for one of the profiles in my data-base. The error is: The code that seems to be the problem is: Originally, it was all on one line and it didn’t work, and now I’ve tried it on multiple lines and it stil…

Find a word from a string in SQL Server

I have some values into a table like below :- Bank Of America testBank Of America State Bank Of India ICICI Bank Test @Bank* I want a query to get all the values which contains Bank only. Proper word should match. Result should be like :- Bank Of America State Bank Of India ICICI Bank Answer One method is to