I have 3 tables: Data in Compania table: Data in Periodo table: Data in VAC_PERIODOCIA table: I want to show all the companies (COMPANIA) and the value in (vac_aplica column) searching by Periodo, whether or not they are registered. I tried this: Result: What I want is this: Answer First of all, the question is a mess: tables and columns
Tag: sql
cartesian product on two tables
I’m trying to create a result set of table names and column names. In table A I have the list of table names and in Table B I have the list of column names. Each table should have the full list of columns. So: Table A table_name Table1 Table2 Table B column_name Column1 Column2 Column3 The result I want is:
How to create query more than two table in SQL?
I found difficulties answering Q2. Q1) Total order value (amount) of the orders placed in the period Jan 2022, from the area Jakarta Q2) How many orders raised for Product = “OPPO A31” in the category = “Mobile Phones” in Jan 2022? And, by how many customers in Jan 2022? Answer Here are a pair of queries for you to
SQLSTATE[22007]: Invalid datetime forma
I try to save some data that it brings me from my view, which is a table, but I don’t know why it throws me that error with the insert. result of insert this is my view: table of view this is my controller: Answer id_tipo_venta seems to be an empty string which is apparently not valid. You can try
Need to Pick Max Date when status = N otherwise No in MYSQL
I have a table which have records like this I’m trying to get the Max Date for each ID which have STATUS = ‘N’. If I get MAX DATE and STATUS = ‘C’ then I don’t want that record. Output : SCRIPT : But I’m not able to get desired output. Answer You can use NOT EXISTS: If the column’s
Deleting duplicates on combination of two columns in oracle
I have a table for example : Port Table S No A Port B port 1 80 100 2 90 110 3 100 80 4 94 106 I want to delete record no. 3 as it is having same combination as record no. 1 how to do this in oracle ? Answer You can use a single MERGE statement and
Set new field priority in SELECT SQL
I have a table of bills with the following structure: What I need is to select all data from table and set additional field “Priority” based on a sum of bill. First 2 rows get priority 1, next 2 rows get priority 2, others get 0: In addition table contains data about bills from various days (field payment_date) and this
NULL MAX(col) value even though DB has a valid record
So I am trying to extract the maximum invoiceNo for current year and this is how I implemented it with PDO: However, $response keeps getting assigned to the else clause : . This is how my DB looks like: Hence I was expecting the $response to be 2022-2. I think there is something wrong with my SQL query and I
Snowflake/SQL: create a time-series table such that every ID is visible, and if ID is null, it uses the previous value? (similar to shift)
Suppose I have the following table: Day ID Value 2022-11-05 0 A 2022-11-06 1 B 2022-11-07 0 C Now given a time window of 1 day, I want to create a time-series table that: The Day column granular unit is 1 day Each Day row displays every ID in the table (like cross-join) Moreover, if for that day, the ID
MySQL Filter on many-to-many on recipes – ingredients tables
In my application, I have 3 tables: recipes ingredients recipes_ingredients I need to find all those recipes that contain a list of ingredients_id and that I have in my food storage and containing NO OTHERS ids outside the list I provided (so not in my food storage). Example: i provide oil (id=111) bread=(id=222) result recipes: OK oil+bread OK bread OK