Suppose you have an entire column in MySQL that is YYYY-MM-DD, and you want to select it as the number of Months to a specific date, and also do it as a new column. Example date counting to can be March 2020. So the following (table_1): Emp_Name Hire_Date Steve 2018-03-28 To Emp_Name Months_Employed Steve 24 …
Tag: sql
How to get in which store did the specific product get the most benefit?
So, here are my tables: Sales id product_code store_id 1 4536 1 2 4674 2 Products product_code product_name price real_price 4536 Red bull energy drink 300 ml 3,68 2,88 4674 Mac coffee 25 gr 2,59 2,10 Stores store_id store_name 1 first 2 second I need to find in which store the product ‘red bull’ …
Add a number for duplicate values in posgresql
I’ve a query in MySQL and I’m looking for a query which can perform below operation using Posgres MySQL Query : Output: Email Row Number Aamir 1 Aamir 2 Aamir 3 Suresh 1 Suresh 2 Hafiz 1 Answer https://www.db-fiddle.com/f/3RqNHRGFjkU74v33upyfhi/0
Complex multi-level JSON and SQL – what am I doing wrong?
So I am able to query my JSON file fine then I wanted to add another field that is under a few levels and when I try to do this – it doesn’t work. What am I doing wrong? So the following works correctly and gives me back the first level promoter id This does not work – I get
Cursor is storing values in a variable but not updating in another table Sql Server
I have write a cursor in which i am getting values from a table using cursor and updating these values in another table . While testing i have analysed that values are storing in table and update is also working because sql server message shows that 1 row has been update but the values from cursor are not bei…
How to count the number of records based on the date and cycle is from Tuesday to Tuesday
I need to write a logic that will give me the data after finding the last Tuesday from the end_date column. I need a report with the logic as mentioned below: If today is 12th April i.e SYSDATE and day is Tuesday then the report should give me only today’s date data only. If suppose the date is 13th Apr…
SQL query to replace multiple occurrences with the most frequent ones
I have a products table, which has the product description in two languages, one in English and one in an alternate language. Let’s say: Product_Desc Product_Desc_Alt A A1 A A2 A A1 A A3 B B1 B B2 B B2 C C1 If I do a GROUP BY statement, there are multiple alternate language occurrences for the same prod…
show who resit and passed and what course was it?
i need help find who fail in exam & resit and pass the exam only, heres the code: heres the result: I need find like this: Answer Possibly using a query like below. this is using your query as input. Also we have assumed that it is not possible to have a student have (PASS, FAIL) for a student on
Graphql nested cursor based pagination, resolver and SQL query
Is there a way to implement graphql cursor based pagination with nested pagination queries in a performant way? Let’s say we have 3 pseudo graphql types: For simplicity let’s say user could read thousands of books and each book can have hundred of pages. user database table: book database table: p…
How to calculate win chance ticket in percentage
I’m trying to calculate a win chance from buying a freebies ticket in the percentage of each user that has been recorded in the database here is my freebies table the total number of tickets is 10 user id 60 have a 5 tickets user id 50 have a 3 tickets user 4 have 2 tickets so I want to