I have 2 Postgres tables with the following structure: Lets say I have data in the tmp table as below: Now I want to write a psql INSERT INTO query which will copy the data from public.tmp to public.mo table and also perform below condition When a Host has mix values in STATUS column, for eg if HOST: RhelTest…
Convert day of week name to day of week number Vertica
With this way – SELECT TO_CHAR(NOW(), ‘DAY’); I can get a day of week name(E.G. MONDAY). With SELECT dayofweek(NOW()); I can get the number of the day of week. (E.G 1) QUESTION: How to convert day of week name to day of week number. (E.G MONDAY -> 1) SMTH like TO_NUMBER(‘MONDAY̵…
How to exclude certain values from a Query [SQL]
as the title states, an NotPrimID, can have two different values Example 1 and Example 2 IF: if NotPrimID does have both values, it should be automatically excluded from the query result. What i want: Query, that will deliever all the NotPrimID, that only have “Example 1” as a result, however if N…
Oracle decode equivalent function to Postgres
So, I’m in migrating database from oracle to Postgres, and this is my error: and here’s my code : do you have any clue? From what I’ve read, some say to replace the decode function with COALESCE, but I don’t have any idea how the syntax is. Answer You could use a standard case expressi…
Oracle SQL Developer limit number of character of datatype char(5)
I was tasked to implement a table with a variable groupcode. There are several requirements. char(5) 2 or 4 uppercase letters plus 1 digit whose value is between 1 and 4 (e.g., AA1, AABB1) Any input other violating point 1 and 2 should be banned The only thing I can come up with is regexp_like but my efforts …
How to include OPENJSON in View?
My JSON object is stored in the table (single cell). Right now, I’m reading the cell and saving the value to @json NVARCHAR(MAX) , but that obviously doesn’t work in views. How can I do something like this? Answer You can use cross apply to apply openjson() to each and every row of your table:
Adding parameter to SQL query
I want to get some data from Excel table using SQL-query inside macros. My code is: If I try using sql = “SELECT * FROM [Page 1$] WHERE Job = 2”, I have no errors. How could I paste Value2 and Value1 values inside my SQL-query? Answer Try like this
How to filter rows that has multiple condition MySQL
I have a table that contains my product details Now I want to write a query that gives me product_id(s) with this conditions: Brand = Intel model = Core i7 I’ve tried this one but it didn’t returns any rows, I guess I should use JOIN. Answer Use group by and having: Or better yet, using tuple equa…
Merge Null Values in Merge Command
i must merge multible database tables in a node js windows service. so i decided to write a method that creates a sql string for this. here is my method: this method and the created sql string works nice, expect in one case. if the value in the source table column is NULL the target will not be updated. here
How to work around Django’s lack of composite keys in this complicated case?
I can’t seem to figure out how to work around the lack of composite keys in Django for the following case. I’m going to write the schema I’d like using SQLite3 dialect. (The only thing below that might be unfamiliar to someone who knows SQL but not sqlite is sqlite’s “WITHOUT ROW…