Is it possible to change the result only if there’s more than one? My query brings this result: Date Code Description Amount 01/01 1001 Produt A 1234 02/01 1001 Produt A 2345 03/01 1001 Produt A 3456 If I have only one produt, that’s fine. But if I have more than one, it shows like this: Date Code Description Amount
Tag: sql
SQL – How to use a value from INSERTed table
I am trying to insert a new location record in my db … and then reuse the value of the newly created id in a select statement’s where clause later on. But I’m getting a syntax error. Code: The error is “Must declare scalar variable” and it dies on there WHERE clause in the SELECT statement. I also tried something
How to get list of ids into separate column
Problem statement: I have a table master_tab which consist of two columns e_id and owner_id. I want to list down the e_id’s which belong to owner_id 72 and 73. There is another condition that analysis_comp flag should be 1 in the table transaction_tab. My attempt: Tool used: SQL Developer(18c) Current Output: Expected Output: Is it possible to get only the
How to write SQL statement to select for data broken up for each month of the year?
I am looking for a way to write an SQL statement that selects data for each month of the year, separately. In the SQL statement below, I am trying to count the number of instances in the TOTAL_PRECIP_IN and TOTAL_SNOWFALL_IN columns when either column is greater than 0. In my data table, I have information for those two columns (“TOTAL_PRECIP_IN”
PostgreSQL: Using CTE with IN
Learning CTE right now, the following query is super basic and it doesn’t really have any useful value but I don’t understand why it doesn’t work The error I’m getting is “ERROR: column “cte_actors” does not exist” Currently using postgres 14 and DBeaver Answer You need to SELECT from the CTE:
Can I ask Firebird to use index (with like on strings) in left join condition on other column?
I have table structures: I can query this and SQL used indexes both on doc_date and on account: But when I am filling the selected_accounts table with data: And I am trying to use condition in left join: Then SQL is not using index on journal_entries.account data, it is using index on je.doc_date only. Can I give some hints to
How to count the number of a value in each month and year? SQL
how can I count the number of ‘cancel’ value in each month and year? Thank you! MS SQL expected output: ETC…. Answer You can start trying something like this: The column [date] should be datetime. If it’s text you will have to cast it:
How to get the 2nd record for a customer purchase?
I’m working on a customers database and I want to get all data for their second purchase (for all of our customer weather they have 2 or more purchases). For example: I want to display the second order which is: I’m facing some difficulties in finding the right logic, any idea how I can achieve my end goal? 🙂 *Note:
Insert row into an empty table with INSERT … SELECT … FROM command in SQL
I’m going to make a new table (PersonInformation) with columns of another one(Members) and some more columns like “Username”, “Password” and “PersonId”. The command I used is: ‘INSERT INTO myTable(Columns_in_PersonInformation…) SELECT (Columns_in_Members + new_columns) FROM Members, PersonInformation WHERE Members.id = PersonInformation.PersonId’ I have two problems, the first one when the PersonInformation table is empty. The result is “0 rows affected”
Pythonic way to optimize SQL VIEW count to extract information schema metadata from Snowflake
I have 12 VIEW tables in Snowflake and I would like to extract TABLE_NAME,CREATED,LAST_ALTERED from Snowflakes INFORMATION Schema for View tables, and also want to get row count for each 12 VIEW tables, along with metadata for Base table mentioned in below code.I was wondering if there is way get row count using below code for 12 VIEW tables or