Category "sql"

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,

Slow MySQL query on 2mill record table despite indexes

Struggling to understand why my query is taking ~8-12s to complete when my table has millions of rows. I can force it to use a specific index, and depending on

Compare date filed with month and year in Postgres

I have a date field in one of my tables and the column name is from_dt. Now I have to compare a month and year combination against this from_dt field and check

create shema databse using XSD in mysql

I have a shema database in file type XSD this file contains descriptions of all tables. My question is how I can use this file to create a database in MySQL. i

Redshift split single dynamic column into multiple rows in new table

With a table like: uid | segmentids -------------------------+---------------------------------------- f9b6d54b-c646-4bbb-b0ec

Getting the "size" of a view in Redshift

Essentially, I'm trying to figure out the size table foo will be after executing: CREATE TABLE foo AS ( SELECT * FROM my_view ); My gut tells me that the

Redshift split single dynamic column into multiple rows in new table

With a table like: uid | segmentids -------------------------+---------------------------------------- f9b6d54b-c646-4bbb-b0ec

ORDER BY field from a comma separated subquery

I'm trying to order a query based on the comma separated result of another query SELECT t.field1, t.field2 /*, ...*/ FROM table t /* ... */ ORDER BY CASE W

Why DISTINCT keyword is decreasing my search time and increasing performace in SQL Server

I am new to SQL and SQL Server and I am using SQL server 2012. but recently I encountered a weird thing while working with SQL server. I got that adding DISTINC

Meta Recruiting SQL -- Join Part 1

I have done my best to neatly format the meta recruiting question below. My current query that I'm trying to ascertain the ratio is this. Returning correct 2/3