I have a table with >50 columns. I have the names of two columns. However, I would like to sum the values of these 2 columns as well as all the columns between them (>50). It seems very impractical to type all the column names in a sum statement. Is there a query for this? I am using SQL Impala by the way.
Related
IS there a way in SQL to make multiple rows for a common column, show up in one?
For example I would like this output:
to show up as:
I believe this article contains solutions to your question -
SQL Query to concatenate column values from multiple rows in Oracle
I have a one-column table that can vary in size depending on the day. Let's say the table has 6,000 rows. Is there a way you can pivot this table in T-SQL so that is 6,000 columns without having to specify each column name?
I have two tables table_1 and table_2.
Both tables contain 250 columns each, with an ID code which allows the two tables to be joined, many to many. Each column row has a value for ranging 0 - 500, with the exception of the ID codes.
I need to do some further analysis, and would like to be able to produce a temporary table or query output where, for each row for each column, the value is set to 0 or 1, where 1 is where the sum of the column by id code is >= 1.
I can do this using case when, but with 500 columns I wonder if there is a more clever way of doing this. If it helps, all the columns in each of the tables end in the word "_bin".
You haven't specified SQL server version, starting from SQL 2012 you can also use IIF or CHOOSE logical functions for this instead of 'case when' but it still require to do it for all columns.
more details here :
https://www.mssqltips.com/sqlservertip/2570/new-logical-functions-in-sql-server-2012-iif-and-choose/
Can I transpose results in SQL just like I have it in excel. No hard coded values as I have different results every time.
For example, I have a table of employees and I want it to just convert rows into columns and columns into rows.
Thank you.
We have a huge table and one of the column contains queries like e.g. in row 1
1. (((firstname:Adam OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Individual
and in row 2 of same column
2. (((firstname:Adam* OR firstname:Neil ) AND lastname:Lee) ) AND category:"Legal" AND type:Organization
Similarly there are few other types of Query strings which are used eventually to query external services.
Issue is based on certain criteria I have to group and remove duplicates from this table.
There are few rules to determine grouping of Strings in different rows.One of them is that if first name and lastname are same then ignore category and type values, therefore above two rows will be grouped to one. There are around million rows. Comparing Strings and doing grouping is not looking elegant solution. What could be best possible solution using sql.