actually, I found many solutions for my issue but I didn’t understand how to apply to my issue! my issue is I have the following SQL statement: what I need is to replace the following part in one part: to get the all columns in one subquery with the same conditions? Answer I don’t know your data s…
Tag: sql
How to select a specific number of rows and convert them into named columns
I am hanging on this problem for hours. A very simple query: SQL Result: RoomId WaterMeterNumber 95E5ACE0-FEE4-4D33-BC22-0DCF7B1155CF SZ12800491 95E5ACE0-FEE4-4D33-BC22-0DCF7B1155CF 3375791 95E5ACE0-FEE4-4D33-BC22-0DCF7B1155CF 45332 95E5ACE0-FEE4-4D33-BC22-0DCF7B1155CF SK9649 And I want the query result to be…
Adding rows to a table respecting the key columns structure
I have a very large table, which follows these structure (I past it here simplified): Product Line Name Quantity Unit Cost Pepe 10000 Lucia 4 UD 8 Pepe 20000 Santiago 7 UD 5.5 Pepe 30000 Mariangeles 10 KG 6 Antonio 10000 Naiara 4 KG 8 Antonio 20000 Toni 7 KG 3 Vanesa 10000 Lucia 4 UD 8 Vanesa 20000 Santiago
Using CAST in MYSQL Query, It works in localhost, But in the server not working
In mysql using cast, I wrote the query like Accnno – varchar SELECT * FROM books where category = ‘Book’ ORDER BY CAST(Accnno AS int) DESC LIMIT 0,10 The above query is working fine in the localhost, But is not working in the server, It shows error like You have an error in your SQL syntax; …
How to turn a number to zero if the result of a calculation is negative inside a squareroot in BigQuery?
I have a query that can result in a negative squareroot, leading to an error. I’m using BigQuery. Is there a way to turn the result in to a 0 if inside de POWER() function is less than 0? Here’s my query: The negative squareroot can happen here: So, if the result of is less than zero, I would like
How do I correct my sql query(s) so i don’t get the error “keyword UNION not expected”?
I have one (possibly two) troublesome raw sql queries in a python flask API. I think the first sql query is causing this error, but I am by no means a master at sql. The database is DB2. The full error is as follows: “[SQL0199] Keyword UNION not expected. Valid tokens: FOR USE SKIP WAIT WITH OPTIMIZE.&#…
Finding Cumulative progress with SQL
I have a SQL table as below : I need to calculate the cumulative progress. for example S1000 have three f1 score. the progress calculation formula is (95 – 87) + (87 – 80) for S2000 the calculation would be (75 -17) + (17 -57) How to achieve this using SQL Answer It looks like your progress score …
User Permissions error for reading from view in postgres
I am using postgres and have a new read-only user that has read permissions on all tables in a base schema. I was trying to SELECT some data from a particular view from base schema and was able to see the values from the view. To test the data count I had to make some changes in the view definition
SQL Use Value from different column on same Select
I have a question if this is possible which will save me time writing extra code and limits user error. I need to use a value from a column (which has already performed some calulcation) from the same select then do extra calculation on it. I encounter this a lot in my job. I will highlight the problem with a
Check if all values in a column falls into a specific group
I have the following table: and I want to check ALL values of the column ‘Token’ and return a flag string to designate what condition is met: when all records are in group (A, B) –> return ‘Condition1’, examples: when all records are in group (A, B, C) –> return ̵…