Category "sql"

SQL Segmentation

I have this table Customer Amount Date Period Group 77766 50 2022-02-28 1 2 77766 20 2022-03-31 2 2 77766 30 2022-04-30 3 3 12345 50 2022-02-28 1 1 12345 20 20

SQL CROSS JOIN with WHERE CLAUSE not returning anything

I am trying to get a result for the query: SELECT product, exportcountry FROM is_exported_to CROSS JOIN is_produced_in WHERE product = cheese AND origin = 'Fran

Adding constraint to check if the value contains specific characters- SQL Server

My Check constraint conflicts when adding values, any answer to why it is wrong will be much appreciated. Here is the question: Ensure that the Student’s

How to retrieve data from previous 4 weeks (mySQL)

I am trying to write a query to get the last 4 weeks (Mon-Sun) of data. I want every week of data to be stored with an individual and shared table. every week d

Sql function to remove values from follower table that are common in unfollow table

I want to calculate total followers of a person from follow and unfollow table using SQl. Form of table are as follows Follow table: Unfollow table: My tries:

Tuning slow query to SYS tables

I'm monitoring the slowest queries to my databases and this one can't be indexed: USE [Project] SELECT TOP 10 t.NAME AS TableName, t.object_id, mai

How to generate an equivalent of pandas.DataFrame.describe in bigquery SQL?

In Pandas, you can get an overview of the table (mean, quantiles, count and count of unique values) for all columns by using the following method: pandas.DataFr

row_number is not unique for duplicate records

I am trying to find the latest update of a particular row from a bunch of rows per uuid. For that we use row_number() over a partition as shown below, "row_numb

Query to show data checkin , checkout, breakin breakout in 1 row

I have structure data like this, I'm using SQL Server: ID User_ID CheckinTime Date 1 110 "2022-03-25 06:30:29" "2022-03-25" 2 110 "2022-03-25 12:12:31" "2022-

Query to show data checkin , checkout, breakin breakout in 1 row

I have structure data like this, I'm using SQL Server: ID User_ID CheckinTime Date 1 110 "2022-03-25 06:30:29" "2022-03-25" 2 110 "2022-03-25 12:12:31" "2022-

Migrate data from multiple columns of table to only one column of oher

Is there any way to migrate multiple columns data of table to only one column of other? I need to migrate the data of table 1 subject varchar(45) body

Find which where clause is the most troublesome

Problem background I am trying to pin down to what condition(s) are causing no records / rows the most, so to allow me to find the root cause of what data in th

How do I set up an SQL table to save week days and time in each event record

I'm looking for the efficient way to store week days and times of each event. How do I achieve the following result Events table id name dates rel_id 1 hello w

Get generated keys from single insert statement with multiple values

i'm inserting multiple rows into a table using a single insert statement. The table has an auto increment field as the primary key. Like so: INSERT INTO MyTabl

Bigquery: Match IP address to IP CIDR in another table

I am referring to this article in order to lookup IP addresses to country: https://cloud.google.com/blog/products/data-analytics/geolocation-with-bigquery-de-id

Fill nulls with lag, but ignore nulls isn't supported

I have a table which looks like this: ID money_earned days_since_start 1 1000 1 1 2000 2 1 null 3 1 3000 4 1 2000 5 2 1000 1 2 null 2 2 100 3 I want that rows

SSIS When viewing query preview some characters are replaced

I have huge amount of data in Sybase DB and I made OLE DB connector in SSIS where I succesfully connected it. We are using charset = cp1250, because we have dat

How do I update a BigQuery table with multiple auto incrementing values?

I have managed to generate a single column based on multiple counts with different prefixes, as detailed here. But now I want to update an existing BigQuery col

Order by calculated column with alias inside case expression

I've got a problem with my order by clause when using a calculated column with an alias as below: This order by works without any problem declare @Mode int = 1

Table relationship problem for an competition program (tennis/Padel)

I am trying to make a my first relationally table structure for a tennis/Padel competition program that registers the scores (sets.)of dubbel matches(4players).