I have a complex query joined to multiple tables to show a “transaction history”, I want a quick and easy way to count the occurrences of order_id to make it as the line_number. I had it done with code but for performance reason I want to have it done with MySQL. Here is an example of what I have:…
Get all days in a month excluding weekends postgresql
I want to write a query sql for postgresql that can basically return me all days of a month excluding weekends. For example (For 11/2019) : First Week: 11/1 Second Week : 11/4 -> 11/8 Third Week : 11/11 -> 11/15 Fouth Week : 11/18 -> 11/22 Fifth Week : 11/25 -> 11/29 I can’t find any postgre…
Get the dates of two weeks from today from database
I have some dates in postgresql database. I want to find dates from today to next two weeks or 14 days. How i can find the dates between current date and next 14 days? This query is not working. I …
LEFT JOIN returning no results if a WHERE clause is added?
I’m trying to add the dbo.EmpHRSchedule.Type = ‘HOLIDAY’ entries to the Hours column only if they exist. To my understanding, a LEFT JOIN would only return entries if they match, and return NULL for non-matches. When I uncomment the AND ehrs.Type = ‘HOLIDAY’ line, no results are …
Advices to implement child comments on comments (How to set it up)
I am working with Laravel and have created a morphable comment table with laravel. Now I want to implemnt the reply function so people can answer to comments. I only do need the first level of …
Ranking subcategories while keeping order of ID
I have the following table: I would like to rank the subcategory (cat2). Desired outcome: I use DENSE_RANK with PARTITION BY to get the following result: Statement: As you can see, the only thing I’m missing is the order of the result. Currently, the rank is based on the alphabetic order of cat2. Howeve…
Try to define a left join only with where condition
I try to find a particular SQL statement to replace an old SQL query. To summarize, I try to make a left join only with where conditions. Here is my test environment: I fill the tables with some data: The usual way for a left join is this: This query returns 1266 rows. But in the old application, which I
Unexpected token “” was found following “”
Im a newbie to DB2. Im trying to convert this sp from Microsoft SQL server to DB2 Here is the sp from Microsoft SQL: and this is the sp after i converted to DB2 Then i got this error: An unexpected token “” was found following “”. Expected tokens may include: “”.. SQLCODE=-…
SQL:pivot: convert each row into many rows depends on a condition
I have been trying to solve this but could not figure it out. so this is the table and more columns could be added: So if the value is one then I will display it in a different row but with the value being the column header itself My boss suggested using pivot to solve this but I am open
MySQL Query with distinct on a column value
I have this table (with 100k+ rows): room_id | emote_id | count | since —————————————- 1 | 22 | 718| 1577135778 1 | 23 | 124| 1577135178 …