I have been finding original balances on bonds from an “Acquisition” table, for individual “performance” quarters. It has worked for every quarter, but when I attempted to run my query on 2010Q1, I received this notice: My query is: Zero balance code is telling how the bond defaulted, …
Tag: sql
Oracle query to calculate current age
I want to calculate current age of person from DOB(date of birth) field in Oracle table. Data type of DOB field is varchar and the is date stored in format ‘DD-MON-YY’. when I calculate current age …
ILIKE and NOT ILIKE in aws redshift different from total
I ran three following queries in amazon redshift: The count was 1554. The count was 62. The count was 85. The last two (62 + 85) should equal 1554. What am I missing? Answer Double-quotes are for identifiers: “myColumn” Single quotes are for values: ‘value’. Your examples contradict th…
Python -SQL String Escape Wildcards
I tried to see if this question had been asked, which it probably has, but I couldn’t find an answer. I am querying MS SQL Server from a python script using pyodbc. I am defining a function to query …
Count number of records in subgroup while keeping a number of records in a group
I have a table with the following structure (it’s a simplified version, just to show the idea): name | city —————— John | New York Thomas | Berlin Hans | Berlin Boris | …
Conditional UPDATE in MySQL
I am trying to UPDATE values from a table, but I need to add some conditions. I found the function CASE, but I am not if it is the best method. Here is an example. My table is ‘relation’: userid1 | userid2 | name1 | name2 I got for example: Output: 4 | 3 | bill | jack and I
Is there a way to query and find out the version of Vertica installed?
I searched the Vertica documentation for the keywords Version and Version Number. But I couldn’t really get any mention of SQL query to select the version of Vertica installed. I thought there would …
Convert Date format into DD/MMM/YYYY format in SQL Server
I have a query in SQL, I have to get a date in a format of dd/mm/yy Example: 25/jun/2013. How can I convert it for SQL server? Answer I’m not sure there is an exact match for the format you want. But you can get close with convert() and style 106. Then, replace the spaces:
Weekday number regardless of the NLS settings
I’m looking for the simplest way to determine the weekday number for the DATE value in oracle independent of the NLS settings. Any ideas? Answer ISO weeks start on Monday; they don’t use NLS settings. I think this expression is reliable. To show how the arithmetic works . . . current_date is a Wed…
Select random rows with no duplicates
I need to select a random amount of rows but also ensure that the rows don’t contain duplicate Image values: ImgID Image 1637 PM1371564839.jpg 1638 PM1371564839.jpg 1639 …