Skip to content
Advertisement

Tag: sql

SQL query that returns the primary key if found, NULL otherwise

Given a table like I am looking for a query that searches for a given name, returns the id if found, and NULL otherwise. Sort of what left join can do, except here there is no left table. Answer Use aggregation with MAX() (or MIN()): An aggregation query like this always returns exactly 1 row with 1 column and if

Why does (SHAPE).SDO_ORDINATES(1) syntax fail, but (SHAPE).ST_PointN(1) succeeds?

Oracle 18c: In a related question, we determined: The syntax of extracting collection elements by index is not supported in SQL. So a query that uses this syntax will fail: (shape).sdo_ordinates(1), Source: Why does SHAPE.SDO_ORDINATES(1) work in PL/SQL, but not in SQL? However, I have a query that is similar (different datatype) that succeeds when I use seemingly similar syntax:

How to construct SQL query to get the output as below

the below image is how the table related and the expected output result. I used MySQL version 6.3.3. and the below is currently can be achieved. and below is the SQL query code Anyone can help me to improvise the SQL query code above to get the expected output is very appreciated and thank you very much… Answer you can

String array to int64 conversion

I’ve two tables and I need to join them. But the common field are of different data types. Table A – ID field is of string array and Table B ID is of Int64. Tried to cast String array to Int 64 getting error “Invalid cast from ARRAY to INT64” Is there anyway I can convert and join the tables.

mysql single column condition query on a multi-column index

suppose a table has only one index : idx_goods (is_deleted,price) and is_deleted column is either 0 or 1 my query looks like this : where price < 10, which of the follwing behavior is this case: 1 mysql do a full scan on the secondary index for price match 2 mysql partially scan the secondary index for price match where

TSQL “where … group by …” issue that needs solution like “having …”

I have 3 sub-tables of different formats joined together with unions if this affects anything into full-table. There I have columns “location”, “amount” and “time”. Then to keep generality for my later needs I union full-table with location-table that has all possible “location” values and other fields are null into master-table. I query master-table, However some “location” values are dropped

How to create temporal table from current and history?

Let’s say I have a current table that looks like this: and I have a history table that looks as such: How can I build a temporal table such as the following in pure SQL? I am using a PostgresDB is dialect helps! I know I can do this in Python, I’m stuck on calling dynamically named columns using the

SQL – Running of SP sums the first row as NULL

I’m trying to develop a SP for Transaction operation , The SP gets as parameters the Username of the player , The Transaction amount, and the Type of the Transaction if it’s Deposit / Draw . My problem is when the first row enters to the table my TotalAmount column in the tables the sums the total amount by Username

How can I generate an ID column for a column in SQL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 months ago. Improve this question I have a column that I’d like to generate an ID column for. How can I do this using SQL?.

Advertisement