Dynamic pivot combined combined with static aggregates I have a table that looks something like this: I basically need to: Group by a number of fields (Place, State, Category in the example) Count per such group Sum MCount, Cost (and others, not in example) per group, these columns are static Pivot over Categ…
Is there anyway to test the function in SQL?
I have following problem. I’ve made an function which checks dates, warehouse if it’s full, etc.. Here is the code and I’ve added comments so it is more clear and understanble: So basically if I run only the function I don’t get any error. But when I run it with the test date I get fol…
SQL – If id exists in table1, then insert record into table2
I have the following problem. I have an accounts and a scoreboard table and I try to reset all values on the end of the month in the scoreboard by inserting a new record with the value 0. SET @mid = (…
Columns in SQLPlus report display longer than database column size
I have a number of sql reports that used to work fine. Recently however they have started to be outputted with the column widths being longer than they should. According to Oracle’s documentation if a column in an sql report has no explicit “COLUMN” definition at the start of the report, eg …
MS Access From Wide Format to Long Format New variable Union ALL
I’m a newbie at MS Access and need some help. I have a table that looks like this: ID HDD CDD HDDKEY CDDKEY 186 -1 -1 1 5 and would like the following: ID HDD CDD KEY 186 -1 0 1 186 0 -1 5 My …
How to find duplicate entries in the table
I am trying to find duplicate entries in the table but if I use Code only in the script then it will give me the duplicate entries in the table. But I want to get all the information from the table …
Match Columns in Table A to Row Values in Table B to update another Column in Table B
I want to match columns of TableA to values in one column of TableB, in order to update values in another column in TableB. TableA: 001100 001200 003000 004000 005000 1 0 1 1 0 TableB: Column_1 …
UPDATE VALUES OF COLUMN IN POSTGRESQL
I have 4 tables: what i want is to update table1 with the salary values from matchsal table with conditions in the others tables, i tried this query: and i got this error: ERROR: more than one row returned by a subquery used as an expression SQL state: 21000 Answer I found the answer ^^” It is simple th…
I tried solving this problem by using MAX function but get the result . Is there a way to solve it by using any other function?
I need to get “second updated_time” for each order and sorting them by “update_time”. I wrote the following query, which is not giving any output. Suppose, we have to calculate get the time difference between second updated time and first updated time against each order_id ,if we sort …
MySQL: Extract Select in “Module”
Assuming the following SQL statement: The there a way to modularize the statement, for instance, extract the second select statement in a file and call this file instead of writing the whole query? Answer I found a way to reuse SQL. Its possible via SQL-Functions and SQL-Procedures