I have a couple tables (pega.race exists too we just don’t need any of the data for this) What I want is to get an average result for each combination (permutation?) of speed/strength/wind/lightning/water/fire in a range. So from 0-2.25, 2.25-4.5, 4.5-6.75, and 6.75-9. They have to be within 0-9. No val…
Tag: sql
SQL: use CASE with AS
I’m working on a long SQL request and I want to use CASE inside but I don’t know how to write it. My request looks like : I want to add something like : I tried to add this at the end but it didn’t work : My goal is to edit key along its value Answer You can do
SQL JOIN tables and and sum columns with the same PK
Here are my tables: Players Name DoB Ranking Ben 01/01/1999 1 Tom 02/01/1999 1 Sam 03/01/1999 1 Sam 03/01/1999 2 Ranking Ranking Points 1 100 2 50 I want to join the tables and add the total points for each player then output this table. Output Name DoB Points Ben 01/01/1999 100 Tom 02/01/1999 100 Sam 03/01/1…
Optimizing select union select oracle
I had an interview recently and the recruiter told me to make a query on a table USERS with two fields (name, age) which should return a list with two columns | NAME | MAJOR OR MINOR | My response was this : Then, he told me that is correct, but we can do better! So, my question is: How
Postgres: Where value equal decimal value
My table looks like this: When the WHERE clause is equal to value with decimal point I get no valid output like: Output: transponder_id = None When the query is for integer value, query works correctly: Output: transponder_id = 1009 Also using BETWEEN query returns expected values Output: transponder_id = 101…
Summing cumulative views in an sql table by date Snowflake
I have a sql table with date, reference number and views as a column, I am trying to add up the views for each row based on the date grouped by the reference number. I have data for 3 days, lets say the 27, 28, and 29 of March, I have multiple reference numbers but lets take 1 reference number:
Trying to create procedure in snowflake and getting error while passing value to another procedure
Below procedure to get the value from the metadata table and pass its value into another procedure. Give the error message: Execution error in store procedure GET_RESULTS: SQL compilation error: error line 1 at position 16 invalid indetifier ‘STBL1’ At Statement.execute, line 18 position 26 Answer…
Return Date Ranges based based on a given interval between two given dates in SQL
I am trying to get a list of all DateRanges of a given interval between two dates. For example if I have the dates 2015-04-01 and 2015-06-20 and when the interval is 20 the result should be Here is the query I am trying Its returning the below result which is not exactly as my expected result above Here as
How to use LEFT JOIN and limit result to one row based on a count
Let’s say i have 3 tables: Table ‘post’ id title 0 titleA 1 titleB 2 titleC Table ‘comment’ id id_post text 0 1 blaa 1 3 blbb 2 5 blcc Table ‘like’ id id_comment vote 0 1 +1 1 5 -1 2 5 +1 I need to get a list of post with the most liked comment. The query sould
Using the function SPLIT_PART twice in PostgreSQL?
I have a TEXT column where each text is formatted as such: /customers/{customer_id}/views/{id1}~{id2}/ I am trying to fetch the id2 only. My idea is how to split the string by the / character first, where I will have: customers, {customer_id}, views, {id1}~{id2}. And then, get the last position: {id1}~{id2}. …