Need sql query to display row numbers in table - numbers

I need sql query to display row numbers in table. I am working in Mainframes and we use SQL queries to connect to oracle tables . I need a query to display row numbers in a table , table doesnt have a column for row numbers . In Mainframes we can input sql queries alone . Any help will be greatly appreciated!!

You can use ROWNUM Pseudocolumn.
Example
SELECT ROWNUM,a.* FROM employees a;

Related

SQL Script in DAX ( Many different Joins )

I have a problem in Power BI with DAX, i want to do SQL joins in Dax , i made my data modelling with my tree tables
Table 1
enter image description here
table 2
enter image description here
table 3
enter image description here
I want to do with DAX this table joining in this SQL query
enter image description here
I want to create a table with the joining bloc
Can you help me ?
Kind Regards ;
I try to do it on power query but i have some speed issue
In power bi, you would address this by creating relationships in the model:
https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-create-and-manage-relationships
Please note that all joins are equivalent to outer joins in SQL. Some of what is in your ssample query is not valid SQL syntax - you can't have duplicate table names, "join" is repeated. However, if you wish to filter a table like T3.U2 = 'NW', you can simply add that as a WHERE clause in the query to import the data into the model or filter out the rows you want with PowerQuery (using the edit queries dialogue in power bi).

postgres crosstab with unknown number of columns

I have a table test with looks like the following
That should be transformed to the following table
I can achieve that with the following crosstab statement
SELECT *
FROM crosstab( 'select category, month, sum from test) AS ct(category text, r202208 float, r202209 float);
However this only works when I know the columns beforehand, but the table contains how much money I spend in each category and each month, so I don't know the months upfront. Is it possible to autogenerate the the columns based on the content in the month column of the original table, maybe by using a postgres function?
Of course I could generate the sql query dynamically as string and execute it with java, node or something else. However I get the data as csv from my financial institute and the original table is just a view, so I would like to create that table without the help of external programming

DB2 : Need to get the list of columns and distinct value counts for a given db2 table

For data profiling purpose , I just need to get the idea if a columns in a given table has values populated or not. For that, I need to get the list of columns and distinct value counts for a given db2 table.
If you are using Db2 for Linux, Unix or Windows you could try
SELECT TABSCHEMA, TABNAME, COLNAME, COLCARD FROM SYSCAT.COLUMNS

How to create SELECT STATEMENT that will loop and then create the sql statement?

I am trying to create a query that will read all rows in table 1 and show them concatenated as if they are one word.
I tried different solutions with no luck.
Imagine a table (CUSTOMER) contains 3 rows (CUST1, CUST2, CUST3)
I want the result of a select statement to give me(CUST1CUST2CUST3) as one row
Notes: I cant use procedures, and if possible the statement should be in PostgreSQL please.
Thanks,
You can use string_agg function to concat rows in postgresql as follow :
SELECT id, string_agg(employee, '')
FROM CUSTOMER
GROUP BY id;

How to get last/Bottom row of the table in Sqlite via Sql Query

I am trying to fetch the last row of my sqlite3 db.
can anybody tell me the query syntax.
SELECT field
FROM TABLE
ORDER BY field DESC
LIMIT 1
assuming that ordering by DESC puts your last row first