I am making a join with two tables, tab_usuarios (users) and tab_enderecos (address). tab_usuarios structure: id_usuario nome usuario 1 Administrador admin 2 Novo Usuário teste 3 Joao Silva jao tab_enderecos structure: id_endereco id_usuario cidade uf 2 1 cidade SP 20 2 Lorena SP 22 2 Lorena SP 24 3 Campinas SP 28 4 Lorena SP I have this simple query
Tag: sql
From keyword not found where expected error in oracle
Need to create a temporary table employee by inserting values from already created table person which belongs to people database but getting error from keyword not found where expected Answer You’d then use CTAS (Create Table As Select), not an invalid INTO clause; it is used for different purposes. Based on comment you posted, there are several options you might
Convert string date format MM/dd/yyyy HH:mm:ss.SSSS to timestamp presto
I have a string that looks like: I am trying to convert this to a timestamp as follows: but i keep getting an error: Answer The value in your example matches the format of timestamp literals in SQL, so you can convert it to a timestamp type by just casting the value to the desired type:
Need to get appropriate/expected row number in Oracle PLSQL
Getting the following output when i use the below query But the expected output should be as below (Refer RowNumber column) Answer First find “groups” each of those rows belongs to (partitioned by refnum and name) (that’s what the temp CTE does), and then apply dense_rank to fetch the final result. Sample data (simplified, as I don’t have your tables):
Change Two Rows Into Two Columns
Oracle newbie here just trying to learn something. I have a query that returns two rows per ID: Current Output Instead of two rows, how can I put the two varying values in the B1_CHECKLIST_COMMENT column into two separate columns? Visually, here’s what I’m looking to achieve: Desired Output I’m using Oracle version 12.1. Answer You can use PIVOT: Or
selecting all rows except top row using offset in MySQL
How can I use offset clause to get all rows except the first row. I am using query like But this is not working in MySQL. what am I doing wrong here? Answer Sadly in MySQL OFFSET only works together with the LIMIT clause. So you need to use or I have chosen that limit number from a different question
How to convert 1900-01-01 to null in snowflake
My SQL query output looks like this. ID UPC 1 2021-05-01 2 1900-01-01 UPC is a date column. How do I convert 1900-01-01 to null? I tried following instructions from this, but I am getting SQL compilation error: error line 1 at position 22 invalid identifier ‘DATE’ Answer Using NULLIF: Returns NULL if expr1 is equal to expr2, otherwise returns
mismatched input error when trying to use Spark subquery
New at PySpark, trying to get a query to run and it seems like it SHOULD run but I get an EOF issue and I’m not sure how to resolve it.. What I’m trying to do is find all rows in blah.table where the value in col “domainname” matches a value from a list of domains. Then I want to
Continuous subset and ranking using sql
I have a dataset like below: Now, I need the output as below: For this purpose, I wrote a query but it is not giving me the desired sequence. My query is as below: It generates the output as below: But in the rank section I need something as below: So, what exactly am I doing wrong here? Here are
How do I filter a list through a lookup dictionary in jinja2
How can I filter a list in jinja2 to generate a list of values from a lookup table? I have a situation where I am using Jinja2 to generate SQL. I have a list of values and I want to replace them with a list of transformed values based on a lookup: In my template, I want to be able