Category "sql"

MySQL Create View with Sequence Numbers for Each Group

I've seen a similar solution on this site but it's not usable in a view due to variable use limitations: Generating Sequence for Each Group in MySQL A table s

Oracle Pivot with 3 Tables

I am using a PIVOT to combine two rows with the same ID into a single row: SELECT B1_ALT_ID, B1_CHECKLIST_1, B1_CHECKLIST_2 FROM B1PERMIT A JOIN BCHCKBOX B ON A

join produces wrong results though the joining columns are of same datatype. Right results are after casting them to different datatype

I have an interesting problem to find the root cause. Inner join 2 tables on 2 columns, but the results are not expected. The data types for both columns are th

Where Condition on google auto complete address

I have a home search table with have a city column which can have multiple cities like "Avignon, France|Nantes, France|". Addresses are "|" separated. There's a

Selecting values in a partition where a condition is met (Teradata SQL)

I have table that is in the following format: Number Departing Arriving Departure Time Removal Indicator 1 Miami Dallas 1 PM N 1 Chicago Dallas 3 PM Y 1 Dallas

What is the best way to get a decimal or a float result when dividing two numbers in SQL [duplicate]

I declared a variable @avgMis as a decimal(2,2) in SQL Server. Then I tried to divide two integers, expecting a decimal value. Instead my answ

How to convert this timestamp in PLSQL?

Using PL/SQL I have a TIMESTAMP(6) like this: 21-APR-22 02.25.00.000000 PM. I need to convert it to format YYYY-MM-DD HH24:MI:SS (EX: 2022-04-21 14:25:00). EDIT

Find dates with lower revenue than yesterday

I'm fairly new to BQ SQL and am stuck on a query regarding dates. I have a table that consists of customer_id (int), date_purchase (date), sales (int). The quer

Condition in creating view - liquibase xml

I want to make some view but with condition in my fourth column. CONDITION: If epr.j_id is not null then fill lj.id BUT WHEN epr.j_id is null then fill 'NONE'

Rspec and SQL: Index 0 is out of range

I am trying to run my code and I get the following error: Failure/Error: Bookmark.new(id: res[0]['id'], title: res[0]['title'], url: res[0]['url']) IndexError:

How do I extract a date (dd-mm-yy) from a timestamp with timezone (timestamptz) in postgresql

My date column "timestamp" is currently listed as: 2020-11-16 20:27:38.033 +0000 It's formatted as timestamptz and I've tried every search on here and google to

Subtraction in same table in same row with where condition #SQL

Using a SQL query to subtract in same table: Table1 grade record total_amount ------------------------------ DSP receipt 17258 DSP sales 16

Can anyone help me on how to fetch MySQL table/s data in JSON format by querying itself which is similar to MS SQL Server

Below is the existing T-SQL code which generates table data in JSON format just by using the keyword FOR JSON PATH, include_null_value. How to implement the sam

SQL Pivot table?

Hi I am looking for a SQL Script the can pivot the following table Every values in ObjectClassProperty column must become columns. ObjectInstanceProperty will

How to use MAX function in MySQL with the having clause

I am working with the employees table in SQL and I would like to fetch the data for max count of employees SELECT (COUNT(emp_no)) AS emp_count, dept_no FROM de

Mapping only one row with JOOQ MULTISET

how to use MULTISET to map only one row rather than a list of rows. Classes: class User { private Integer id; private String name; private Integer p

PostgreSQL: How to add element to nested JSON array?

select rooms from users where username='test_user'; **returns** {"roomID":[{"1":"test1"}]} I want to add to[{"1":"test1"}] this {"2": "test2"} --> [{"1":"t

oracle insert on subselect gives ORA-00936

I am trying to insert into a table, whose values are same except few from the same table with max sequnce number based on an ID. insert into ENT_ROLE_USERS_HIST

How to get sum of multiple rows in a table dynamically

I am trying to get the total sum from columns of a specific data type(money) for multiple tables in a database. Currently I am able to get the list of columns f

Getting duplicate results from DB

let absent_remove = result_database.filter(item => item.absentday != absent_days) console.log("absent_remove", absent_remove); I got this piece of code, I h