Suppose I have a table, like this: MyTable How can I get the number of occurrences a name appears in a given column, and then display that number to new column? For example, this would be my desired output: Instinctively, I want to use something like However, this not only omits the Number column, but it also…
Tag: sql
Oracle developer. ORA-01722 Invalid Number when using UNION
I have this problem: I have two tables: Table A and Table B, with the same column called PK_COLUMN that in both tables are numeric(8, 0). I want to make this union: And I got the next error code: ORA-01722 Invalid number. The problem is that when I execute the both parts of the union separately they work perf…
how to set concatenated string parameter in preparedstatement
I have the following java code: I get the following exception in codeline 3-: Invalid column index What did I do wrong? how to set params correctly? Answer Take the bind parameters out of the string literal: Or, create a single bind parameter and pass in the concatenated value:
How to multiply two columns and add a new column to the database?
Which customer id bought maximum products? (hint : get sales by multiplying product_quantity and price_per_item fields) This is how the database looks like After adding the sales column I am not able to perform the sum operation and getting the following error: SELECT customerid, product_quantity * price_per_…
If a string is enclosed in quotes either ” or ‘. I have to remove those starting and ending quotes in snowflake
Check the following input/output examples: Input: “”Nag”ndra”” -> Expected output: “Nag”ndra” Input: ‘N’agendra -> Expected output ‘N’agendra I tried the below query to implement that behavior, which is able to remove the starting a…
Select last nontrivial value from each column, by group
How might I write in SQL a query that accumulates a table of rows representing selective updates into a single “latest and greatest” row per BY group? For instance from the following table: index date ssn first last title car shoe 1 Apr 1 100-00-0001 Joseph Schmoe Analyst Honda Adidas 2 May 1 100-…
How to select data depending on data from the same table with custom field in SELECT?
I have a query to fetch closest airports to the airport: Where 55.966324 and 37.416573 are latitude and longitude of the airport I’m searching neighbour airports for. But in order to get those coordinates I would need to fetch that airport data first in a separate query which would slow things down. I w…
SQL UPDATE on with data from same table
I have a next situation with a table, Need to update rows from rows in same table, as you see here: TABLE ID SN FID 1 12345 1 2 1122 2 3 12345-RG NULL 4 1122-RG NULL I need to UPDATE row 3 from row 1 Column FID(Same SN, different ending only on the end -RG) Update row 4 FROM
Using column from another table in trigger
I need to use a column from another table when i use trigger before insert but i get an error Unknown table in field list Here is an example code: the column from another table is “printing_time_hr” from table “slicer” Please help, what to do, how to use the column from another table A…
convert varchar[ ] column type to uuid[ ]
there is a column of type character varying[] , which contains data of type uuid like {0f071799-e37e-4e1c-9620-e580447416fe,913a7134-6092-45fa-ae18-163302db8112}, but there are also some old values of another type like {5edfd4edfa1bb21a142442a0}. How can the column type be converted? I used the script: alter …