Category "sql"

Grouping ranges of data

I have segmented linear data to identify the minimum and maximum begin and end values of each range, now I want to consolidate overlapping ranges. This is easy

How can I write a case sensitive WHERE CLAUSE in SQL Server?

Ok, this one has me stumped. I'm hoping it's not something stupid/obvious... I'm trying to fix addresses in a client database. I have a function that takes a

How to delete a record from database where all fields are the same to another?

I have two only records in a database table and I want to delete only one of them. The problem is that I don't have any primary key nor unique identifier, so ho

Are nested SQL queries atomic?

I have some micro service (almost) system where each program has its own port. Moreover, not all ports in the system are available. For simplicity, I decided to

How to reuse a computed value multiple times?

Basically I just want a simple way of finding the most recent date in a table, saving it as a variable, and reusing that variable in the same query. Right now t

How to pivot between current day and previous days

I'm using Access SQL I have data that looks like this:- dealdate value 17-Apr-22 267 18-Apr-22 274 I'm trying to make the data look like this (there will only

How to re-run Diesel migrations?

I'm using Diesel with PostgreSQL. I added my migrations, and they worked fine, outputting everything in the schema.rs file. Until I noticed that I was missing t

Using Pivot to remove duplicated results adding new columns

I have the following table [_teste_calendario_Table] and when "Monstrengo" has the same value, I'd like to make a pivot, adding new columns "De1", "Ate1", "Ven

How to use Knex object in other file?

How do I use the knex db object inside other files? For Example my index.js const app = require("express")(); const cors = require("cors"); const bodyParser

How to use a temp sequence within a Postgresql function

I have some lines of SQL which will take a set of IDs from the same GROUP_ID that are not contiguous (ex. if some rows got deleted) and will make them contiguou

Visual Studio SSAS Tabular Model does not show existing connections

I'd like to write a SQL Query to extract data from a SQL Table into the SSAS Table. I do not have this option available, as normally I should go over 'Model' &g

'The variable name '@' has already been declared. Variable names must be unique within a query batch or stored procedure.'

string subject= "INSERT INTO Subjects (ThesisNo, [Subject]) VALUES (2, @subject)"; SqlCommand commandSubject = new SqlCommand(subject,con); string temp

How to update multiple comma seperated values in a single column in sql

Question on SQL Suppose there is a table.

SQL Query to find maximum, average, minimum of temperature

I was attending a question in hackerank advanced SQL certification, i came across a question like to find the maximum, minimum and average of temperature . i wr

How to avoid double counting while using SQL

I have a transaction table which contains date, transaction_id and category (it is a sales table of clothes). It looks like this: ndate transaction_id category

How to build query from SQL by Doctrine QueryBuilder?

I'm new in Doctrine ORM, and I need help with building QueryBuilder command. I have a SQL command and I need covert to QueryBuilder. $qb = $this->entityManag

Unique Address SQL Query [duplicate]

I have a table like this: I would like one address for each account number, if the account number has two addresses, I want to get the one wi

ERROR: extra data after last expected column on PostgreSQL while the number of columns is the same

I am new to PostgreSQL and I need to import a set of csv files, but some of them weren't imported successfully. I got the same error with these files: ERROR: e

How to pivot a table in Presto?

Let be a table named data with columns time, sensor, value : I want to pivot this table on Athena (Presto) to get a new table like this one : To do so, one ca

MYSQL not getting the sum zero values (having no entries of that id) against distinct id of another table

SELECT d.millid, d.bookno, d.partyname, d.count, d.counttype, d.orderqty, d.dispqty, d.pending from ( SELECT b.millid, b.count, b.counttype, b.bookno,