Category "sql"

SQL Server combine case with convert statement

Hi im stuck with this query, what i want is to get one column "fecha_registro_convertida" with the condition of the case statement but also with the CONVERT sta

Does it matter to filter results when doing aggregation?

I want to get my sales for each day which is located in my orders_summary table. orders_summary table columns: id, date, amount, sku_id products table columns:

Retrieve the last value of each data group - Oracle SQL

I’m having trouble on a query right now to retrieve only the last value saved for each group of results. I explain myself with a table. I have these value

Create table from simple UNION statement

What is wrong with this union? first 'select' and ')' are incorrect create table GL_ALL ( select *from GL1 ) UNION ( select *from GL2 ) UNION ( select

Oracle SQL - table type in cursor causing ORA-21700: object does not exist or is marked for delete

I have problem with my function, I'm getting ORA-21700: object does not exist or is marked for delete error. It's caused by table type parameter in cursor, but

How do I create a table with multiple auto incrementing values?

I would like to have an autoincrementing string in my BigQuery table. This seems like a good way of doing it: CREATE TABLE dbo.YourTable ( ID INT IDENTITY(1

How to Generate Date Series in Redshift?

I would like to generate a sequence of dates in Redshift. I can easily do it in PostgreSQL using the generate_series() function. This function works in Redshift

How to sort one column and then another within it in SQL? [duplicate]

I have this table state num ------------------------- ca 20 ny 30 ca 50 ca 10 ny 70 ny 90 What I want is to p

Update all affected rows with specific values on PostgreSQL

I have the simplified version of the table I have below. Each row has an item_order value partitioned by its parent_id. item_id item_name parent_id item_order

PostgreSQL Crosstab Query

Does any one know how to create crosstab queries in PostgreSQL? For example I have the following table: Section Status Count A Active 1 A

C# SQL query with user input

I tried to make software that could be use as a database for libraries so I started to learn SQL I alredy did way to save a book into the database but I am stuc

mysql null value case when is null does not work

I have following query to handle null value and flag those based on two table join however c.pure_proc_flag is null then 0 else 1 does not provide the result

Unpivot/Transpose in Presto SQL

I have a dynamic table in the format shown in the image (left hand side). A new month column will be added every month. How do I unpivot month in Presto? I can

insert the last 30 date in an oracle table

I need to create a table where we have one date column. I need to insert the date from yesterday to yesterday-30 days.Table output should look like this There

SQL Error when using Order By for SQL database query in PowerBI Desktop

Getting this error when using Get Data with PowerBI Desktop to connect to SQL database Microsoft SQL: The ORDER BY clause is invalid in views, inline functions,

Ms Access Date function not passing in LIKE query

I want to query records from the access database that matches the current date (system date) The following query works fine if I enter the date literally. SELEC

Create/Query different tables based on conditional statement in BQ SQL

To illustrate with an example, say I have two tables in BigQuery called "fruits" and "vegetables" respectively. I want to have a variable at the start that lets

Regular expression not working Sybase ASE 16.0

I am trying to retrieve IDs from a table in Sybase ASE 16.0 The query has to return IDs starting with AB or BC. Example AB0001 AB0002 BC0001 BC0002 The regular

PK on temp table failing

I have a trigger which declares a table variable. DECLARE @TREarn_aaa table ( aaaID bigint NOT NULL PRIMARY KEY, Bbb decimal (18, 8) NULL, Ccc dec

Is there any way to filter by the first child using SqlAlchemy?

I'm trying to find a way to filter by the attribute of the first row returned as children. class Parent(Base): __tablename__ = "parent_table" id = Colum