I have 3 tables: Table 1 id | email —+———- 1 | a@a.com 2 | b@a.com 3 | c@a.com 4 | d@a.com Table 2 order_id | email ———+————– 1 | a@a.com 2 …
Tag: sum
replace value with 1 and apply SUM method in one query SQL
I need to replace the value in column imp from 1-0 to 1 and sum it up. Column imp is a STRING, so it also needs to be converted to INT. Each line represents the record so I need to sum up imp and group by another column (in order to get the number of records for a specific Advertiser)
Rolling sum based on date (when dates are missing)
You may be aware of rolling the results of an aggregate over a specific number of preceding rows. I.e.: how many hot dogs did I eat over the last 7 days SELECT HotDogCount, DateKey, …
Find the max date to last one year transaction for each group
I have to query in sql server where I have to find for each id it’s volume such that we have last 1 year date for each id with it’s volume. for example below is my data , for each id I need to query the last 1 year transaction from when we have the entry for that id as
SQL query grouping by range
Hi have a table A with the following data: I’d like to have the following result: My DB is DB2/400. I have tried with ROW_NUMBER partitioning, subqueries but I can’t figure out how to solve this. Answer I understand this as a gaps-and-island problem, where you want to group together adjacent rows that have the same PA. Here is an
Add value of type B to type A of same org_id
I have a table like this Now I want to select values from this table for each org_id, type but for type A i want to add value of type B of same org_id to type A. My query should return this In this case, when ORG_ID is 1 and TYPE is ‘A’, I have to add that organization’s type
Is there a way to dynamically execute queries in SQL without using user defined function?
I am currently working on the table containing some documents data, focusing on the columns containing date of document and net income. What I have to do is to write an sql statement which will result …
Is there a way to return non existent values when using groupby and union all?
I have a table that I’m trying to return summarized results from for a chart that will have two datasets, one for debit transactions that have happened each month and one for payments that have happened each month. The table I’m querying looks like this: What I’m looking to get back out of my query is a result that does
How to multiply all values in one column to make one number?
In SQL Server, I am trying to multiply all values of a calculated column in a table in descending date order, to produce one number. This is so I can calculate a factor that can be applied to a different table / value, i.e. multiplying every value in the “price rate” column to produce a “price factor” So far I
Mysql subtract and sum
I have a below table in mysql. DROP TABLE IF EXISTS `mdc_data`; CREATE TABLE `mdc_data` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tariff_id` int(11) DEFAULT NULL, `msn` varchar(100) DEFAULT NULL, `…