Skip to content

Tag: sql

Conditional debit from credits and running balance using SQL

I’ve data like below in a table cryptotransactionledger id transaction_typeid transaction_type amount totalcoins 1 1 bitcoin-credit 30 30 2 2 ethereum-credit 20 50 If I spend bitcoin, I’m putting a new entry like below in the same table with transaction_typeid 3 and similarly for ethereum with tra…

Rank Date based on today’s date

I have a simple date dimension, I’m attempting to write a Window function (without much luck..) to net the following result. where 1 is today and 0 is yesterday. What can I try next? I’m unsure what to search for. Answer Assuming the dates are continuous, we don’t even need analytic function…

Query condition where a value is in a comma separated string

I have a table in which one of the table columns third_row stores a comma-separated list of numbers as a string but when its value is A then it means a combination of all the possible numbers. How do I approach this so that the query returns all the rows that have the third_row as A and the rest where

SQL command not properly ended in Python OracleSQL

I’m having some trouble with SQL code that works when I run it in DBeaver, but when I execute it with cx_Oracle it comes up with the error of: The python code is good, but I’m not much of a SQL programmer, so maybe someone can look to see if there is any obvious coding errors. It’s just weir…

casting date within a to_char function?

How can I cast a date or timestamp column to date within a to_char function? But I need to cast the date_column to date first but am unsure Thanks Answer TO_CHAR, as you are using it above, appears to be Oracle code. MySQL uses the DATE_FORMAT function: