Skip to content

Tag: sql

Using ORDER BY to pair values in SQL ORACLE

I need to use ORDER BY in a query that uses UNION. The query returns the following: CRN Inv_1 Inv_2 GBP -100 -100 GBP -400 -400 GBP -500 -500 GBP -700 -700 GBP -800 -800 GBP -10000 -10000 GBP 100 100 GBP 400 400 GBP 500 500 GBP 700 700 GBP 800 800 GBP 10000 10000 Expected Output: CRN Inv_1

Error => #1242 – Subquery returns more than 1 row

I am selecting order data from my orders table with that I also need the order product’s count which contains a specific word Account TopUp 200, Account TopUp 500, Account TopUp 1000, The order contain multiple product means one order contains both(Account TopUp 200, Account TopUp 500) and other product…

MySQL Where condition with CASE

Here i want like if cksp.status is not null then condition should be cksp.is_include_in_pipeline = 1 ELSE ignore the where condition Answer That logic should be similar to:

Is there any way to use CASE in WHERE clause in Oracle?

I have the following data in DB which supposed to be a date but in number format: date_col: 20200130.95656 20200910.85213 0 20220101.55412 0 0 20220730.85626 Now I need to format the dates to mm/dd/yyyy so I used the following command in oracle: to output it like this 07/30/22. But the problem I still need to…

How to write an array literal in SQL?

Is it possible to use an array literal in Oracle, such as: Or: Or what’s the simplest (i.e., possible not in PL/SQL?) way to do this? Answer if you wanta flexible list, y an use a type like this ID | INTLIST -: | :—— ID | COLUMN_VALUE -: | ———–: 1 | 1 1 | 2 1 | 3

Oracle missing FROM clause

Is it possible to create a CTE without a FROM, and if not isn’t that the whole point of a CTE in the first place? It seems a quick-fix for this is just adding FROM DUAL whenever needed. Is that what’s supposed to be done? Answer Yes, that’s exactly what dual is supposed to be used for. Selec…

ODBC – Exclude weekends in SQL

I currently have this SELECT statement which allows me to get yesterday’s date: However, when the day is Monday, I need the result to return a value date for Friday and not Sunday. When the day is Tuesday to Friday, it would be the SELECT Statement mentioned above. What would be the right code line to a…