I have the following DB2 table: COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE COLUMN_TEXT DMPROD -2 CHAR () FOR BIT DATA 35 Product Code DMPTYP -2 CHAR () FOR BIT DATA 1 Period Type DMTYPE -2 CHAR () FOR BIT DATA 6 Type of Data DMVL01 3 DECIMAL 17 Value Period 1 DMVL02 3 DECIMAL 17 Value Period 2 DMVL03 3 DECIM…
Tag: sql
Oracle SQL – Splitting string every 70 characters without splitting a word and deriving sequence number
I currently working on a table on Oracle and I need to split one its field (RH02X) into multiple rows when it the field exceeds 70 characters but I also need to make sure that no word would be cut. I am only allowed to use SQL without PL/SQL. For example, I have the following data from the table test_remarks
SQL query for top N people as per spending in each state for top M states
I have a table with 4 columns (about 10M rows) I want to get the “Top N people as per spending in each state for top M states” using an SQL query on the table. I am using PostgreSQL. Can someone help me out? Note: There are multiple entries per person and per state. However, 1 person can live only
how to convert a table to another in SQL (similar to pivot, but not exactly)
I have a database table looks like this in the below, in SQL Server 2016: (the max rows for the same ProjectKey is 3) I want to write a query to be able to convert the above table to the following: If it can be achieved by writing a SQL query that would be great. Anyone can help? Thank you
SQL query in Java with enum return error of Incorrect integer value:
I get this error massage: java.sql.SQLException: Incorrect integer value: ‘xACxEDx00x05~rx00… the query is working, but if I put the category name (Category.Electricity) its return error. I call it with statement.setObject(…) meybe this is wrong..? the main class: the enum class: the method:…
INNER JOIN twice form the same table
I have 2 database tables that I want to JOIN. DB table 1 had football fixtures in it. So Team A plays Team B and the score was. The data comes from an API and in this DB table the teams are numbers instead of actual names. In the second DB table I have a list of all the teams
Flag items not having the specified combination in a column
I need to flag ID#s not having a specified combinations of DC and Storage Locations. For example: Articles must have the following combinations for each DC: DC Storage Location DC01 ABC, BCA, DCA DC02 ABC, BCA DC03 ABC, DCA My desired outcome would be the below as I’d like to show the Storage Location m…
SQL, retrieving only entries that all the IDs of its many-to-many relation are in an array
need some help with a SQL query. Below I wrote an example of what I want: I need to retrieve entries that the user has privileges to see all of its components. The privileges are stored in an array, for example, I’m a user with the following privileges: [1,2,3] In the database, I have a table with the f…
SQL query to remove duplicates from single column based on latest date
I have a table where I have duplicate values in just one column, and I want to remove those value using the column which has timestamp values. So the value which has latest timestamp should be in the expected result. For example, using the below table column1 is varchar, column2 is timestamp Looking at the ab…
Cycle detected while executing recursive query
I am using CTE recursive query to get below output but don’t know why it is throwing “cycle detected while executing recursive WITH query”. Can anyone please tell me where is wrong with my query? my query: SELECT order_id, product_id, quantity FROM cte; table/data script: Answer In the recur…