Tagged Questions
0
votes
0answers
39 views
How to improve the performance for SQL Server Count(distinct()) and Sum() functions? [closed]
The below one is my query. It's taking 12 seconds for the execution process. The count(distinct()) and SUM() functions are taking long time for execution. I tried it after create the non-cluster index ...
2
votes
1answer
123 views
Is it possible to make a reference to the result of an aggregate function in a SELECT clause from the same SELECT clause?
I'm not a Database Administrator--just a Software Engineer. I would like to know if it is possible to reduce the following T-SQL query:
SELECT
SUM(Price * Quantity) as 'Total',
SUM(Price * ...
19
votes
7answers
4k views
Writing a simple bank schema: How should I keep my balances in sync with their transaction history?
I am writing the schema for a simple bank database. Here are the basic specifications:
The database will store transactions against a user and currency.
Every user has one balance per currency, so ...
2
votes
3answers
206 views
Non-deterministic aggregated result
Why is my query non-deterministic?
I have query that do the following:
select sum(float1*float2*coalesce(float3,1)) from table
When I run this query I get a deterministic result, but it seems not ...
5
votes
2answers
630 views
Using totals on aggregates to improve performance
I have two tables: details and totals of these details.
Details (Slow solution):
select
OrderId = r.OrderId
, TotalQty = SUM(r.Quantity)
, ...