I have a table named PAYMENT. Within this table I have a user ID, an account number, a ZIP code and a date. I would like to find all records for all users that have more than one payment per day with …
Tag: sql
Getting the floor value of a number in SQLite?
I have a SQLite database with a table containing the scores of some league players in a bowling center. I’m trying to get the average of the Score column for each player ID. The problem with this is I only need the whole part of the average, and it should not be rounded (example: an average of 168.99 sh…
sql query with a case when returning more than one row
I’m trying to do a query with a case when condition to see what list I will show but I’m having this error ORA-01427: single-row subquery returns more than one row. the query is this: is it possible to call a query with more than one row inside a case condition? Answer I would do this in multiple …
SQL Server Stored Procedure to Send Email
This is my first attempt at writing a stored procedure that emails someone. When trying to execute I get these errors: The code that I am using which is causing this is: Answer You’re missing a comma after the @body line, which is throwing off your declarations. Add it here:
SQL speed up performance of insert?
I am performing some test on sql server and I want to get the best insert speed possible. The statement I use is something like this: INSERT INTO db_Test_databse..tbl_test with(rowlock) ( …
Convert a SQL query result table to an HTML table for email
I am running a SQL query that returns a table of results. I want to send the table in an email using dbo.sp_send_dbMail. Is there a straightforward way within SQL to turn a table into an HTML table? Currently, I’m manually constructing it using COALESCE and putting the results into a varchar that I use …
Group by every N records in T-SQL
I have some performance test results on the database, and what I want to do is to group every 1000 records (previously sorted in ascending order by date) and then aggregate results with AVG. I’m actually looking for a standard SQL solution, however any T-SQL specific results are also appreciated. The qu…
SQL: How to get the count of each distinct value in a column?
I have a SQL table called “posts” that looks like this: id | category ———————– 1 | 3 2 | 1 3 | 4 4 | 2 5 | 1 6 | 1 7 | 2 Each category number corresponds to a category. How …
SQL calculating time between assignments
I have to write an SQL statement which contain a field that contain two different values consecutively but in the way I have wrote it, it return always null because it is interpreted as having the two value in the same time! My conditions should be : (ci.field = ‘Group’ and ci.oldString = ‘T…
Filtering Django Query by the Record with the Maximum Column Value
Is there an easy way to filter a Django query based on which record has a max/min value in a column? I’m essentially asking these questions, but in the specific context of Django’s ORM. e.g. Say I have a model designed to store the historical values of everyone’s phone numbers. with the reco…