I’ve got a following table: How can I do ‘select Status where Name XXX represented at least in one Array[i].Name’? Answer
Compare records in same table using self join
I am looking to get Permanent employee who has joining date greater than manager. This is what I tried till now, but I get zero records. I am expecting ouptut as Epmoyee with Id 9 as it has joining year(2019) greater than both the managers(2017 and 2015) Answer The join condition on id is the problem; this is…
How to select and join field with max date?
I have two tables joined on RECID and AAATRANSPORTORDERRECID : AAATRANSPORTTABLE AAALTLCHANGEREQUEST I need to select the record shown from AAATRANSPORTTABLE and join the AAALTLCHANGEVALUE value for the most recent CREATEDDATETIME from AAALTLCHANGEREQUEST. My query is as below: It produces these results: My d…
How to find the drinker who ordered most amount of drinks in MYSQL?
So far I have been able to find the amount of drinks in a single day for EACH drinker. SELECT DRINKER, ODATE, COUNT(DRINK) TOTAL FROM ORDERS GROUP BY ODATE, DRINKER ORDER BY TOTAL DESC, DRINKER ASC;…
Converting complex SQL with FULL JOIN to Linq
I am trying to convert a SQL statement to Linq/Entity Framework, and am having a difficult time. Below is the SQL. The FULL JOIN and the GROUP BY seem to be what I’m struggling most with. I’ve reviewed this SO answer and I understand how to execute a FULL JOIN on its own, but can’t figure ou…
How to count the number of occurences for a specific value from a range of columns using T-SQL?
I have a table (t1) as shown below that contains single-character values in all columns named v%: I need to count the number of occurrences for “O” and “E” and display them in 2 additional columns. How can I do this? Expected Output: Answer I would use apply and aggregation:
SQL Select only missing months
Notice the 2017-04-01, 2018-02-01, 2018-07-01, and 2019-01-01 months are missing in the output. I want to show only those months which are missing. Does anyone know how to go about this? Query: …
MySql query to check list of ids if they are friends with me?
So I have a list of ids(userId’s) that was found using a sql command that I want to check with my friends table to see if they are indeed friends with myself, a userid I will provide with, and have a column that will represent if they are and also group them if they are my friend and not my
Alternative ideas for INTO CLAUSE in DYNAMIC SQL
I just learned,I will not able to use INTO CLAUSE in stored procedure,while using dynamic sql. Below is my Dynamic SQL. SET V_SELECT = ‘SELECT ‘ || SELECT_FIELDS || ‘ FROM …
How to find unique count of each value from a table?
How to count the occurrence of each city within a range? I am a beginner to SQL. I have a table like this: ID City 1 A 2 A 3 A 4 B 5 B 6 C 7 D 8 E 9 C Using the SQL query: …