I have the following select statement (example) which gives back a sum from a table. Select SUM(Salary) from Users d, MoreData m where d.Office = ‘A’ and m.Active = ‘Yes’ and d.id_user = m.id_of_user This works perfectly fine and adds up column salery for all users which are located in Office A abd are marked… Read More Oracle SQL WHEN condition in SELECT statement
I want to create a query like this: For student_name, if the number of grade=0 and grade=1 students is equal, let’s not select this person, but if the number of grade=0 and grade=1 students is different, let’s select this person. In the query I will use for my example, Jack will not be selected, everyone… Read More Selection of rows providing a specific condition in sql
As we all know, if you have a function like this: def foo(): foo() The function will call itself 1000 times and then you get a RecursionError exception. But what if you had a thousand and one different functions that call each other? i.e. a() calls b() calls c() and so on. Would you get… Read More Are there separate call tree depths for recursive and non-recursive calls?
I have something like this… FlightNum Class Seats SoldOut 10 A 0 10 B 5 10 C 15 10 D 25 I want to write a statement where FlightNum is the same, and A class has 0 seats, all rows for that FlightNum should put a "1" in the SoldOut column. FlightNum Class Seats SoldOut… Read More If values in Column A are the same and other values are equal to, then put X in another column
I’m puzzled by how from … import …, class constructor and match…case in Python interact between each other. Given there are two modules, foo and bar. foo imports CONST from bar and tries to use it in Foo class __init__() within match…case construction. This gives UnboundLocalError. The minimal reproducer is below. foo.py: from bar import… Read More Interaction between import, class and match…case in Python
I need to create a new column (insider_class) sorting data from a data.frame` based on specific rules using two columns as a reference. I have a column with several parameters (parameter) and another with values (value). The rule is: If value pH >=6 and <=9 then insider_class=yes, if not then insider_class=no If value DO >=… Read More Use case_when() in R with multiple conditional rules and multiple columns
This is my SQL Query CASE WHEN (1>2) THEN( select * from rate limit 10 ) ELSE ( select * from rate limit 1 ) When I use Case statement like above , I can get error like below. ERROR: syntax error at or near "CASE" LINE 2: CASE WHEN (1>2) THEN( ^ SQL state:… Read More How to use Case statement in Postgresql?
I have this data frame. I need to substr fecha_nacimiento but it has 7 or 8 char. fecha_nacimiento n 1011997 1 31122002 2 i try this fecha_nacimiento <- fecha_nacimiento %>% mutate(year = case_when(nchar(fecha_nacimiento$fecha_nacimiento == 7 ~ substr(fecha_nacimiento, 4, 7))), nchar(fecha_nacimiento$fecha_nacimiento == 8 ~ substr(fecha_nacimiento, 5, 8))) But there is an error in MUTATE. I wish… Read More how i can run case when with diferent nchar vector
| 1dist | 1result | 2dist | 2 result | 3dist | 3result| |——-|———|——-|———-|——-|——–| | 5 | MADE | NULL | NULL | NULL | NULL | | 10 | MISS | 2 | MADE | NULL | NULL | | 5 | MADE | NULL | NULL | NULL | NULL | | 20… Read More How to use SQL sum if with multiple conditions
I have written the following query in SQL Server in order to find the medal tally for the countries based on the count of athletes winning a medal SELECT SUM(CASE WHEN MEDAL = ‘G’ THEN 1 ELSE 0 END) AS ‘Gold’, SUM(CASE WHEN MEDAL = ‘S’ THEN 1 ELSE 0 END) AS ‘Silver’, SUM(CASE WHEN… Read More Case statement to find medal tally for each country