Category "sql"

SQL (MySQL etc), what is the difference about length string (1-256) and (0-256)?

Thanks for reading my post. I wanna know, what is the difference between length (1-256) and (0-256) in sql and how to store them in database?. I was asked to de

Auto-increment in Oracle table when insert in the same table

I have a table and I want to increment a column by 1 when I insert a row into the same table. Table users - when I insert first row value of idusers is 1, and i

How to execute SQL query for selection of info from more than 1 table

I wanted to select values from one table according to another table I have a booking system with 'user' information table and 'appointment table', they have col

SQL query with count distinct using multiple columns

Having the following table in SQL Server: create table [dbo].[stats]( [customerid] [int] NOT NULL, [username] [nvarchar](256) NOT NULL, [source] [in

effective query than AND operator

I would like to know that is there any other effective way or query to get the desired output for the below query with AND operators because if I run this below

How to convert year month type to datetime format

I want to convert value year month ('202101') 2021 > year 01 > month to 2021-01-31(end day) in toad for oracle please help me, if somebody know.

Add column containing status to table based on number of occurrences

My SQL table contains two columns: Order and Order Line. Now I would like to add a third column (Status) to my table to indicate whether it's a single or multi

How do I write SQL query for average?

I have recently attended an interview on SQL. Below is the question: Write a query to retrieve city name, state name, city population and return the following c

searching in range between columns using sqlite3 in pandas

I have found solution to my problem in one question Merge pandas dataframes where one value is between two others I tried to modify it for my situation but it d

SQL convert output from integer to float

The numbers in my results are of type integer, but I want to convert them to float. import sqlite3 connection = sqlite3.connect("mydatabase.db") my_cursor = con

how to get data grouped by ids

I have grouped data in a temporary table according to id_card. There are multiple activities for each card. I want to send 1 email for all activities happened o

PostgreSQL - How to get month/year even if there are no records within that date?

What I'm trying to do in this case is to get the ''most future'' record of a Bills table and get all the record prior 13 months from that last record, so what I

Presto SQL query to calcute percent views

I have to calculate % contribution for each category. SELECT portfolio, (total_portfolio_views*1.00000/total_views)*100 view_contribution_perc FROM( select por

Count overnight hours as one day

I have a dataset where certain operations occur during the overnight hours which I'd like to attribute to the day before. For example, anything happening betwee

SQL query to get what percentage of product categories have never been sold

I have the below 4 tables with relationship # sales # products +------------------+---------+ +------------------

Using Count + STRING_AGG, to display distinct values

I am trying to use COUNT with STRING_AGG. The problem is that in a subquery it counts as needed and I have count 1 when it's 1 employee that is taking the cours

How to fetch only CH_PAY_MODE loan_id from this table?

loan_id coll_date coll_pay_mode 8007571771 APR-2022 CH 8007571771 FEB-2022 CH 8007571771 JAN-2022 CH 8007571771 MAR-2022 CH 8007571771 MAR-2022 CL 8007571771 M

SQL Server Agent alert

I hoping there is a way to get an email alert for which a new distinct data has been inserted in to a column in my views found in the SQL Server Agent - job?

What is the formula in SQL to calculate time/ number of days taken to sell x units of a product since its launch?

As part of a dashboard development, I need to know the number of days taken by a newly launched item to reach sales of 1000 units. This is for benchmarking perf

Why is my filtered index not being used for one statement?

I have the following table (an excerpt follows w/o other columns): USE [opg-systems-dev] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [db