I have a query that includes a subquery that references one of the tables that my query joins on, but I also need to do an evaluation on the field returned from the subquery in my WHERE clause. Here’s the current query (rough example) – My subquery is currently returning the latest date from the c…
Linq tolist() count returns different value from translated sql
I have a situation where the translated sql direct form Visual Studio is returning a different number of records from the Linq. I am expecting 4 items but in the count() of the resulting list I only have 1. This is the case despite creating more records – it always returns 1. Strange thing is I have the…
What will be the query for this?
JOIN public.match m ON (s.stadium_id = m.stadium_id) group AS ( ) SELECT round_number ,stadium_name ,spectators FROM ( SELECT round_number ,stadium_name ,spectators …
Cumulative Sum When rows have the same value sql sql server
I’d like to do cumulative sum of the column SubTotal to get a cumulative RunningTotal column. But I noticed that if rows have the same values, the cumulative sum doesn’t work. e.g. In the below example, the row 5 and row 6 have the same SubTotal value of 838.9178. Because of that, the RunningTotal…
SQL query related to Joins and count
Please clarify my sql query question. I have 4 tables in my sql server example as below: Products —> Id, productname Suppliers —> Id, ProductId, suppliername Customer –> Id, …
Custom SQL response (JOIN TABLE)
I have two tables, table1 and table2 I want to link the two tables with the id, by grouping the information in one and the same answer. table1: ╔════╦══════════════╦ ║ id ║ product_id ║ ╠════╬═══…
SparkSQL query dataframe
I am converted a pandas dataframe into spark sql table. I am new to SQL and would like to select the key ‘code’ from table. query sqlContext.sql(“””SELECT `classification` FROM psyc”””).show() …
Convert from lateral view to case statements in hive
I need to place below code in case statement: I have tried: But getting error. Answer For the provided SQL on table tab1, the actual logic is like: Explode field secondary.tertiary, alias it as lv, which results in a temporary result set (table) tab2; A join-like operation to concatenate tab2’s fields b…
In oracle SQL , how to count the no of records based on conditions
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
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 …