Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [sum]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
24 views

How to efficiently (O(log n)) get the sum over a range (date/time range) of a column?

One column is value in integer. Second column is timestamp in datetime. I want to efficiently get the sum of the values in the first column over a datetime range (start time to end time). Is there ...
Kuelf Deez's user avatar
1 vote
1 answer
22 views

PostgreSQL - Sum all row that satisfy a condition into a single row

I'm trying to extract some statistics from a Postgres database and I made this query: SELECT city, job_count, TO_CHAR(job_count * 100 / SUM(job_count) OVER (), '90D00%') AS job_share FROM ( ...
Mateja Maric's user avatar
0 votes
0 answers
12 views

How to mark a calculated query column as total:sum in Microsoft Access?

How can I ensure for Design View that the "total" line of this calculated column shows "sum"? It seems to change after running the query and saving it. What starts as: TotalRevenue:...
Nick's user avatar
  • 1
0 votes
0 answers
27 views

How is the ! used in Microsoft Access queries?

The "bang" or exclamation point is a logical operator. Just to follow up on a previous question, is it problematic to use "!" with Microsoft Access queries to specify tables and ...
Nick's user avatar
  • 1
0 votes
0 answers
25 views

Interest Accrual and insert monthly records since start date

I need to calculate the (1) "To" date after the initial contribution amount to accrue for accounting interest. The "TO" is calculated as End of month date if no other are events ...
Myran thiru's user avatar
0 votes
2 answers
53 views

Mysql count Same Two or More Same Record as One and Summarize It

Good Afternoon all, I have two same data record or more in MySql table. How i can counting the same data as one and zero if have only one data based on flag status pair. Below is an example of data: ...
epm.007's user avatar
  • 29
1 vote
2 answers
31 views

Comparing an aggregate function's result against a column

i have 2 tables like these; invoices id | total_amount | currency | discount payments id | invoice | amount As you can guess, payments table keeps records of the payment made to a specific invoice. ...
cem ekkazan's user avatar
0 votes
1 answer
16 views

Next Business Date Column

I have a dataset that looks like this. Where business_day indicates whether the transaction_created_date is a business day or not. I'm trying to sum the line_amount so that values that occurred over ...
Lena Zheng's user avatar
0 votes
1 answer
18 views

MySQL Query duplicates sum for left join

I have 2 tables, Greeter_Detail and ZipCode_Details I'm trying to SUM the total of People and Families from and Greeter_Detail and join them on ZipCodes, but I get duplicates. ZipCode_Details has city ...
angel12333's user avatar
1 vote
1 answer
82 views

Limit results of complex query to most frequent values in given attribute

Say that you have the following tables for a multi store platform CREATE TABLE orders ( id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, store_id BIGINT NOT NULL, ordered_at TIMESTAMPTZ NOT ...
nbon's user avatar
  • 113
-2 votes
1 answer
44 views

Using sum and datediff from 2 tables [duplicate]

I am using 2 tables Members (MemberID, MemberName, Department, JoinDate, LeaveDate) Subscriptions (ID, MemberName, DatePaid, AmountPaid) I have combined them SELECT Members.MemberID, Members....
Mark V's user avatar
  • 9
0 votes
0 answers
89 views

Counting Rows From a Value in a SQL text box - please please can anyone help?

I just can't find an example of this anywhere and hoping someone can help. I have a query which returns a list of care services and other fields based on the care service table values and calculated ...
Paula Morrison's user avatar
0 votes
0 answers
23 views

How to Join two tables with SUM in SQL server [duplicate]

i have 2 tables 1.registros 2.servicios what I wanna have is this: id,nombre,apellido,direccion,telefono servicios_pedidos of table 1 + sum of table 2 servicion.precios with table 1 registros.[...
rodrigo 's user avatar
0 votes
1 answer
59 views

Mariadb vs Mysql: Sum aggregate select with outer query column fails in MariaDB

I am having an issue migrating from MySQL to MariaDB 10.11. My query gets an order by an id and calculates the balance for the order by summing the transactions/taxes and discounts via a select ...
Kalki Truth's user avatar
2 votes
2 answers
359 views

How to sum two different queries and group them?

amount from_client to_client transaction_type 200 NA Jacques tsa 400 John NA tsb 800 John NA tsb 800 NA Jacques tsa 100 Jacques NA tsb I would like to get the sum of Jacques and John ...
COPEGUEST's user avatar
2 votes
1 answer
56 views

mysql count of a column based on date and type

I have the following table optimizations select items_type, created_at, count_optimized_items from optimizations where shop_id=126 and count_optimized_items!=0 items_type created_at ...
Apoorv dev's user avatar
2 votes
2 answers
97 views

SQL Sum with break-out (audits on inventory)

I'm having some difficulty getting this mysql query to work. I have the following tables create table items ( item_id int not null auto_increment, item_name varchar(25), primary key (...
Jason Chvat's user avatar
0 votes
1 answer
22 views

merging 2 Queries into one

I have the following queries: Query 1: SELECT agencies.code, SUM(IF(commissions.action = 'collection', commissions.commission, 0)) as collections, SUM(IF(commissions.action = 'delivery',...
user268130's user avatar
1 vote
1 answer
34 views

MySQL Query - Sum data according to Category Parent name - each their own column

Here is the data I have: table agencies: id code 18 agency_01 6 agency_02 table compensations id agency_id compensation_category_id amount registered_at 3 6 4 45000.00 2023-01-01 4 6 5 25000.00 ...
user268130's user avatar
3 votes
3 answers
3k views

Join twice on same table with different conditions and no PK / FK relations

I have the following tables: agencies: | code | commissions: | registered_at | action | origin | destination | commission | I need to SUM(commissions.commission) for the following conditions ...
user268130's user avatar
-1 votes
1 answer
855 views

How to list sum of values in the specific period

Sorry for very newbie questions. I have a table, shown below with values about duration of events. Sometimes I have several events in one hour/day. Instead of showing each particular event, I would ...
Rok Rogelj's user avatar
2 votes
2 answers
47 views

create list of payees with 401k and roth contributions and sum matching amounts

I'm using sql-server. I have a table of 401k and roth contributions plus matching. I need a query that will produce a list of payees with their contribution(s) listed under the correct column with ...
dougfree's user avatar
0 votes
1 answer
101 views

MYSQL - return the minimum number of records so price sum is possible to be as close to the input price

I have a table with names, prices and a user input price, for example, 100. I want to return a minimum number of records so prices sum will be close to the input price So If I have in records items ...
lekinio's user avatar
0 votes
1 answer
155 views

Improving Performance of Group By sum Query to get payment data based on total Employees

I have a query to show payment data paid by grouped total Employee (1,2,3) (their size [how much number of users are in total Employee)) and the total amount. But My query took 30-35 seconds result ...
Abdul Rehman's user avatar
0 votes
2 answers
64 views

How to substruct some table rows from another related table rows and get the SUM of the totale result

I have two table (Orders, Payments) they are 1 to many relationships (1:N) One order can have many payments Table 1: Orders id total_price 1 1000 2 2000 3 3000 Table 2: Payments order_id(FK of ...
Abdelraouf dz's user avatar
0 votes
0 answers
192 views

select by aggregation of fields in json column and sum

Using postgresql 11. Given the following dataset: foo | bar -------------------+-------------------------------------------------- "a" | {'a_count': 1, '...
ChuckE's user avatar
  • 101
-1 votes
1 answer
4k views

SQL Query duplicates sum for each join

I'm trying to do this table which will give me a date, and then sum up sales from a separate table, but the sales values get multiplied 14 times for some reason. Will this need a temp table, or am I ...
Nik G's user avatar
  • 11
-3 votes
1 answer
1k views

How select join sum with 0 returned if not exist

I need some advice. I want to select join with sum. select year(date), month(mon), c.id, c.name, sum(t.trx_detail) from client c left join trx t on c.id = t.id group by year(date), month(mon), c.id, ...
Andreass Pramana's user avatar
0 votes
1 answer
1k views

Add new column based on conditions and the value difference of other column

I think I might be overlooking something obvious here. I'm not asking someone to write the whole code for me, I just need a hint or a link to a similar case. Thanks in advance... My query: select ...
Lorenzo Castagno's user avatar
-2 votes
2 answers
57 views

How sum over work

Given this table: CREATE TABLE Table1 ( [Classroom] int, [CourseName] varchar(8), [Lesson] varchar(9), [StartTime] char(4), [EndTime] char(4) ); then: INSERT INTO Table1 ( [Classroom], ...
SoT's user avatar
  • 107
0 votes
2 answers
423 views

Agregation group by date or group, pair index, MySQL, slow response

I would like to get an advice from you about manipulating lot of data using SUM and GROUP BY two columns. I have a table with 60M rows: mysql> SELECT COUNT(*) -> FROM adgroup_ad_diff; +-----...
atay's user avatar
  • 31
0 votes
1 answer
958 views

MS Access - How to sum matching criteria from two columns in same table

I have an MS Access database with four columns of interest that I am trying to work with. The rows represent sold jobs, and the columns of interest are "OriginalSaleAmount", "...
JDDellGuy's user avatar
3 votes
2 answers
30k views

How to Join two tables with SUM and GROUP BY in SQL server

I have 2 tables product id designation 1 coca 2 Pepsi 3 Fanta 4 Seven 5 Eight 2)sub_product product_id name quantity 1 sm 10 1 lg 10 1 xl 20 2 1L 10 2 2L 20 2 5L 20 3 Ty 10 3 Sa 20 4 ...
Abdelraouf dz's user avatar
0 votes
2 answers
7k views

MySQL: SUM() returns multiple rows when used with joins and grouping

I expected by query, which uses SUM() to return one row, containing the total of all rows. However, it returns multiple rows. SUM() is not adding the rows. SELECT SUM(DISTINCT `sales`.`sale_shipping`) ...
micvelodia's user avatar
0 votes
1 answer
1k views

MySQL: SUM() does not provide sum when used with JOIN

This produces one column with 10 numerical rows: SELECT (`sales`.`sale_shipping`) as `total_shipping` FROM `sales` LEFT JOIN `contacts` ON `sales`.`contact_id` = `contacts`.`contact_id` LEFT JOIN `...
micvelodia's user avatar
1 vote
1 answer
785 views

Calculate running total of "consecutive days without views" for each group, that can restart multiple times within each group based on conditions

Summary I'm working to create a counter metric that shows, for each client's slug, the number of consecutive days of zero views. The counter should increase for each consecutive day that the client's ...
Matthew's user avatar
  • 21
2 votes
2 answers
2k views

Why does a MySQL 'where' clause with Index make a SUM query slower?

I have a table with 5 million records. Table columns are id, customer_id, status, and amount. When I run a query without Index(status), SELECT SUM(amount) FROM `game_results` WHERE `status` = 1 the ...
PanelMaker's user avatar
0 votes
0 answers
75 views

SUM `amount` column based on `transactionType` in Postgresql "transactions" table

I have this table: +--------+-----------------+ | amount | transactionType | +--------+-----------------+ | 10 | Debit | | 5 | Credit | | 15 | Credit | | 20 ...
benhowdle89's user avatar
-1 votes
1 answer
58 views

sum with combination

I reproduce the table in image and result I expect. So, I like sum for each item withe the sum of related item. But some item are null or join to himself. I think some array can help me but I don't ...
pasqal's user avatar
  • 101
0 votes
3 answers
1k views

Query for getting the sum of all unique entries in a column

Currently I'm using mysql to return the sum of all data in a column that have the same word. To do this I'm using the following query: SELECT SUM(CASE WHEN status_to = 'Draft' THEN 1 END) AS draft, ...
JJM50's user avatar
  • 103
2 votes
2 answers
121 views

Group by x, get other fields too (comparing options and performance)

I'm a novice, trying to find the best way to sum up my data. Oracle 19c. I have a WORKORDER table that has work orders (ISTASK=0) and tasks (ISTASK=1). Tasks are children of work orders. Work orders ...
User1974's user avatar
  • 1,467
0 votes
1 answer
45 views

Best practise to compute total amount from individual entries

I want to keep track of the individual and total amount of drinks someone ordered. Table 1 Customer information: customer_id name age 1 Steve 44 4 John 24 Table 2 Drink ...
Tomvkgames's user avatar
2 votes
2 answers
83 views

T-SQL Group and sum record set based on value in a given column

Take the following example: SELECT * FROM [Orders] WHERE DATE = '2021-09-10' Date FirstName LastName Adults Item Description ---------- --------- --------- ------ --------- -----...
Bjørn H. Sandvik's user avatar
3 votes
2 answers
597 views

Zero/NULL Case Trick

In the book Getting Started with SQL, Thomas Nield talks about a technique he calls the zero/null case trick: There is a simple but powerful tool that can apply different filtering conditions to ...
User1974's user avatar
  • 1,467
0 votes
1 answer
422 views

Select Result Different On Float Data Type MariaDB 10.4.8 [duplicate]

On MariaDB I have simple table with float data type CREATE TABLE `testatt` ( `id` int(11) NOT NULL AUTO_INCREMENT, `nilai` float DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=...
febry's user avatar
  • 47
0 votes
1 answer
3k views

SQL sql subquery with SUM for totals

I am a little stuck on getting a total value for a column using the SUM function. I want to get the total amount of items for an order from my database. The DB order is made up of several line items ...
J.Pett's user avatar
  • 1
1 vote
1 answer
266 views

SQLite: How do I use the sum function

The code I am using is here CREATE TABLE timecard ( id INTEGER PRIMARY KEY autoincrement, clock_in REAL not null, clock_out REAL, lunch integer, pay_type TEXT ); INSERT INTO timecard ...
linux478's user avatar
1 vote
3 answers
6k views

Sum multiple columns, based on distinct values in different Columns

I have the following table, in an Azure SQL DB that has duplicate values that I'm trying to Sum. Here is the Logic: If the PaymentID is unique, then Sum Payment, If the creditID is unique, then sum ...
TheDemonLord's user avatar
1 vote
2 answers
3k views

Get rows above and below a certain row, based on two criteria SQL (with SUM)

Say I have a table like so: +----------+---------+------+---------------------+ |student_no|level_id |points| timestamp | +----------+---------+------+---------------------+ | 4 | ...
bb25's user avatar
  • 45
1 vote
2 answers
215 views

EAV - COUNT()/SUM() on column and row values with and without NULLs

Assume that there is a table demo with these data: id userID title data 1 1 DATE 01-01-2021 2 1 COLOR RED 3 2 DATE 4 2 COLOR YELLOW 5 3 DATE 04-01-2021 6 3 COLOR RED 5 4 DATE 04-01-2021 6 4 ...
Drahcir's user avatar
  • 13