I have Event_No, Events, Date Range in my table like below. I need to show Min datetime respective Event name with ‘IN'(a concatenation of (Event-‘IN’))and Max datetime respective Event with Out(a concatenation of (Event-‘Out’)). I need My Final Output like below Thanks Answer Th…
Tag: sql
SQL: how to select distinct values with an offset
Given the following table: id value ——- ——- 0 1 1 6 2 7 3 9 4 2 5 20 6 21 7 3 I’m wondering if there’s a way to select distinct rows where there’s a difference between (integer) values of (for example) 3, giving a priority to id (low id value = more prioririty). Progr…
PostgreSQL: Inserting tuples in multiple tables using a view and a trigger
I am trying to build an order system that is able to insert a compound order that consists of multiple items and amounts. My database layout is as follows: I have an order table, containing an autoincrement id, item_id, amount and order_group_id columns. I also have an order_group table containing an autoincr…
How to sum multiple rows on trigger update?
I wrote a trigger on update on table [CART] to count and insert value to other table [HEADERS] to column [SUM]. It works but only for 1 row where [CART].[NUMBER] = [HEADERS].[NUMBER]. Column [NUMBER] …
UNION 2 tables lots fields, few different, possible use SELECT *?
I have 2 MYSQL tables, one with 794 fields, another with 796 fields, the common 794 fields the same. Yes genuine figures, importing data from old system to new one. If I do: SELECT foo FROM (SELECT …
I’m trying to know the country that pays the highest salary from
select last_name, country_name, SUM(salary) from employees e JOIN departments d ON (e.department_id= d.department_id) JOIN locations L ON (d.location_id = L.location_id) JOIN Countries Cc ON (L….
Sybase ASE: how to print all table rows using cursor?
The following code is supposed to print all rows contained in the temporary table #table_A: However, it results in the following error message: How can I print all rows contained in a (temporary) table? Here’s another way of putting my question: I’m trying to do something like that: Is there a way…
How do I sum up each Month of data for each product?
I have a set of data such as: Date Product Volume 01-01-2020 A 5 02-01-2020 A 25 03-01-2020 B 20 02-01-2020 B 10 04-01-2020 C 5 02-02-2020 …
SQL create extra column which gets data from the table two columns
I have a query which have two fields that I would like to combine as a new column. On excel it goes something like this =CONCATENATE([@CompanyID],[@Year],[@month]) But I don’t know how to create …
Indexing for dense_rank query in postgresql
So been trying to run a query on a big table but it’s taking more than a day to finish, when I put explain at the beginning and went through the result, it did not appear as using an index The query …