I have two Datetime fields that I wish to add together. They are in the following format: ’01/01/1900 00:00:00′. The main issue with this is that I want the calculation to only include working hours. …
Grouped LIMIT in PostgreSQL: show the first N rows for each group?
I need to take the first N rows for each group, ordered by custom column. Given the following table: I need the first 2 rows (ordered by name) for each section_id, i.e. a result similar to: I am using PostgreSQL 8.3.5. Answer New solution (PostgreSQL 8.4)
SQL Count Years on FromDATE to ToDate fields
Suppose i have > ID FromDate ToDate > — ——– ——- > 1 01/01/2005 30/6/2007 > 2 01/01/2008 …
LINQ to SQL – Left Outer Join with multiple join conditions
I have the following SQL, which I am trying to translate to LINQ: I have seen the typical implementation of the left outer join (ie. into x from y in x.DefaultIfEmpty() etc.) but am unsure how to introduce the other join condition (AND f.otherid = 17) EDIT Why is the AND f.otherid = 17 condition part of the JOIN instead
How to think in SQL?
How do I stop thinking every query in terms of cursors, procedures and functions and start using SQL as it should be? Do we make the transition to thinking in SQL just by practise or is there any …
MySQL export into outfile : CSV escaping chars
I’ve a database table of timesheets with some common feilds. id, client_id, project_id, task_id, description, time, date There are more but thats the gist of it. I have an export running on that …
Calculating the closest future periodic payment date in SQL
I’m working on an application that deals with periodic payments Payments are done fortnightly i.e. payment 1: 2009-06-01 payment 2: 2009-06-15 payment 3: 2009-06-29 and now I need a SQL statement …
How can I see the raw SQL queries Django is running?
Is there a way to show the SQL that Django is running while performing a query?
MySQL “Group By” and “Order By”
I want to be able to select a bunch of rows from a table of e-mails and group them by the from sender. My query looks like this: The query almost works as I want it — it selects records grouped by e-mail. The problem is that the subject and timestamp don’t correspond to the most recent record for a
How can I get column names from a table in SQL Server?
I want to query the name of all columns of a table. I found how to do this in: Oracle MySQL PostgreSQL But I also need to know: how can this be done in Microsoft SQL Server (2008 in my case)?