Category "sql"

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

Firebird query returns Buffer

This is my first time connecting to a Firebird database from Node JS. I'm using the "node-firebird" package. Everything seems to work fine. But I get these <

How can I store data from JS into a MySQL database

First things first, I'm new to the forum, anything I write that isn't concise or just flatt out adjective let me know! I'm developing an app that can retrieve d

How to Add Multiple JSON_BUILD_OBJECT entries to a JSON_AGG

I am using PostgreSQL 9.4 and I have a requirement to have an 'addresses' array which contains closed JSON objects for different types of address (residential a

How to generate a range of numbers between two numbers then duplicate entries from that range?

I would love some help with a query to expand an Access Table I'm working with. I need to generate a range between the min and max numbers and then duplicate th

SQL Moving window over two level of groupby

I have the following table of orders for users like the following: CREATE TABLE orders ( order_id UUID, user_id UUID, date date,

Is there a way to check that none of the rows in a grouping contain a value?

I have a query that looks like this: SELECT ordDetails.OrderId FROM orders.OrderDetail ordDetails WHERE ordDetails.Class <> 'O' GROUP BY ordDetails.

Displayed values are not what they should be

There are 2 tables ost_ticket and ost_ticket_action_history. create table ost_ticket( ticket_id int not null PRIMARY KEY, created timestamp, staff bool, statu

Creating A Stored Procedure That Truncates A Table With Foreign Keys

I would like to make a stored procedure in SSMS that will truncate a table that has foreign keys. Here is what I have right now but when I pass a table with for

MySQL dynamically find available reservations

I have a requirement to create a room reservation system with dynamic booking slots (a reservation can start at any time and last anywhere from 15 minutes up to

How do I combine YEAR and MONTH into a DATE?

I'm looking for an easier way to do this. My current code is written as below: CASE WHEN LENGTH(CAST (MTH AS VARCHAR(4))) = 1 THEN CAST(CAST (YR AS VARCH

PostgreSQL year, quarter calculator

Given a year and a quarter, a procedure should INSERT values into table tb_quarter, which is empty and have this structure: CREATE TABLE erp.tb_quarter (

Find the total amount for each day. Amount calculated from all previous days if day is not Monday

This was a question asked in a BI Engineer interview. I could not solve it and still scratching my head around it. Although, I used lag window function using ca