I have table with below structure : I wanted the SQL query to output me the following : Logic : If the values in the Col2 are A,B then it should be summed up as Internal , If E then it should be summed up as External. Answer To map your column values use DECODE, simple providing the list of
Tag: sql
Trouble understanding a LIKE operator syntax
I got pasted a source code to extract a particular dataset and I am having a problem understanding one of the bits. Here’s the part of a query: Could you help me translate what does the inside bracket of this LIKE operator mean? Many thanks in advance. Answer COALESCE takes second argument if first one …
MySQL TIMEDIFF Less than an hour, invalid time
I have a function in MySQL that will select the time someone clocked in, and select the time someone clocked out and link them together. It will calculate how many hours that person has been on the clock in total between two provided dates. I then created another function that selects the break events and sub…
MySQL syntax for summing several count data
I have a MySQL table called things_they_own with two columns: person and thing and my primary key is the combination of the two. Thus, there are several rows where the first column is a certain person with the thing column being different for each, and several rows where the second column is a certain thing a…
What’s the most efficient way to divide a table by a threshold into two sub-queries in PostgreSQL
I have a table test with schema id(int) and height(numeric) in PostgreSQL. I need to divide them by a certain height then calculate each sub-query. To my understanding the two sub-query above will iterate the table twice. In a programming language such as python, i can put data in a list then just iterate thr…
What is the difference in select with alias, and without- oracle 11g
I have a table, let’s name it table1. The table consists of many columns, and one of the columns is an object, which consist of 3 subcolumns, let’s call them value1, value2, value3. Let’s say that …
How to Merge Identical Rows with different column?
I have a table like this: ——————————————– | Job | Class | Employee | PayType | Hours | | 212 A John 1 20 | | 212 A John 2 …
Getting unknown column in on clause when trying to get the latest record
I have two tables orders and order_items I am trying to get the last order_sum for each day using an inner join but I am running into an error in my second join. Unknown column ‘o.last_order_date’ …
mysql gives a syntax error with many joins [closed]
it’s about an hour that I’m trying to understand why this query gives: syntax error near ‘WHERE players.player_user=1 AND players.player_status=0 GROUP BY players.playe’ on line 108 I have mysql 5.6….
How to distinct with condition
I am working on T-SQL. I got a table like this. x y z t 1 avc 45353 11.02.2019 2 avc 24324 29.05.2019 3 frg 54647 30.06.2019 3 dsc 35678 29.05.2019 4 dec 21445 13.04.2019 4 …