Skip to content

Tag: sql

Pivot Issue ORA-00918 column ambiguously defined

I am running the below query and need to output the rows as columns. When I am adding the second MAX statement, I am getting an error ORA-00918 column ambiguously defined. Not sure what I am doing wrong. Any help will be appreciated. Answer You probably need something like this I.e. 1) add alias to you pivot …

SQL MAX() function seems to truncate results

I have the following basic 3 Table Structure in mariadb/mysql. This simple SELECT returns incomplete records. I reduced the output of all follwing examples to a single dataset to avoid unnecessary clutter. The IP_LONG column is missing the follwing for example… My guess is, it has something to do with t…

Why is my group by not grouping my values as expected?

My project is a clothes factory and I have 3 tables. Person : A table that contains people’s name Category : Contains each category of clothes in the factory (sockets, shoes, etc.) Quantity : The quantity of clothes for each person And I’m trying to display something like this : Name Quantity_shoe…

Rewrite NVL and select statement according to string

I have a column, called parametre, which contains our parameters: So i want to get a output FA or DL, according to string PRIJEM_CISTY or PRIJEM_VRATKA: It works. But is there any “better” solution for this ? For example, decode() or RegExp() ? Answer You can put the two together to query

Recursive query compute parent values

I have 2 tables Persons and Sales. In Person there is relation between child and parent, I want to compute 20 percent of parent values with the following condition Persons Sales I want to get result like this I wrote this query but it does not give appropriate result Answer This should be a two steps algorith…

Grouping repeated numbers sqlite table

I have this table and I need the query to show the numbers repeated more than 2 times in which draw. I expect this result I’m doing this: But it doesn’t work. Thanks in advance. Answer You can first transpose your data with a cte and union, and then use group by: