I write this script in SQL server And I want get the food name with the Max of order count From this Joined Table . I can get Max value correct but when I add FoodName is select It give me an error. …
Tag: sql
Mysql IF statement Error on Nested if sentence
I am trying to create a procedure to update the stopTime field on my works table. The query I am using is: update mydb.works set stopTime= (IF((SELECT table_name FROM information_schema.tables …
Display the data that does not exist in particular table using multiple interconnecting table join
I am trying to list all students that did not enroll in this subject yet using the var_subjectcode as filter. I am using the code below but it is not working properly. It keeps on resulting empty …
PSQL query to insert the records from one table to another based on condition
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 has
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’, ‘DAY’); –> 1 (just for example, don’t working) Answer
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 NotPrimID does have “Example 2” also as a
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 expression:
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 are in
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