Category "sql"

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

Query - select multiple rows based on condition

I'm a bloody beginner (working with Access). Suppose that I have two tables with data: list of students list of extracurricular activities I have a third table

CASE statement in a temp table to format a decimal value SQL --> Syntax error

I am trying to use a case select for a $ pay field. If the field is 0.00 then i want the decimal formatted as a blank fill of length 10 0's else give me the dec

How to get the last transaction of each player - SQL Solution

I have a database where I store all transactions made in a game (picture of DB). Now I want to get the value of the last transaction for each player. I already

Querying JSON value in BigQuery

I have a BigQuery table ("activity") where one column ("groups") contains a JSON value (the table is an export of Google Workspace logs). I'd like to be able to

While creating view in Hive SQL, getting error as duplicate column present

create view comb as select * from dept d join dept_part p on d.dept_name = p.dept_name; Error Message as "Duplicate column name: dept_name"

Show members that have a consistent doctors visit, after the first visit till the day of delivery

SELECT DISTINCT DEL.BABY_ID, DEL.MOTHER_ID, MIN(DEL.CHECK_VISIT_DATE) OVER (PARTITION BY DEL.MOTHER_ID) AS Del_FIRST_DATE, (DEL.CHECK_VISIT_DATE)

SQL group by 7am to 7am

How do I simply group by a 24 hour interval from 7am to 7am in a manner similar to: select format(t_stamp,'yyyy-MMM') from mytable group by format(t_stamp,'yyyy

Statistical Tests in R

I want to run Bonferroni P Adjusted Value Test on a stacked data set. This is my code: stat.2 <- stack.2 %>% group_by(modules) %>% t_test(values ~ phen

Can't SET variable in BigQuery | Error: Cannot coerce expression

I'm trying to set variable in order to make further operation. But when I set my first variable on line 2 ("SET(new_user)=( "), I get an error Query error: Can