logo
down
shadow

Select daily amount of specific values from same column


Select daily amount of specific values from same column

By : dapwell
Date : November 22 2020, 01:01 AM
like below fixes the issue Solved! I was able to grab the counts of the individual values using a combination of sum() and case statements.
code :
SELECT
  DATE(timestamp),
  IFNULL(sum(case when satisfaction = 0 then 1 end), 0) as 'unhappy',
  IFNULL(sum(case when satisfaction = 5 then 1 end), 0) as 'neutral',
  IFNULL(sum(case when satisfaction = 10 then 1 end), 0) as 'happy' 
FROM feedback
GROUP BY DATE(timestamp)


Share : facebook icon twitter icon
dplyr: sum of daily values for whole year and sum of specific daily values in the same formula

dplyr: sum of daily values for whole year and sum of specific daily values in the same formula


By : Reuben Amohjohn
Date : March 29 2020, 07:55 AM
Does that help We can do this in a single chain by subsetting the rain for non-NA 'value' with is.na
code :
res <- df %>%
        mutate(year = factor(format(date, "%Y"))) %>%
        arrange(site, year, parameter)  %>%
        group_by(site, year, parameter ) %>% 
        summarise(sum_rain = sum(rain), 
            specific_days = sum(rain*value, na.rm=TRUE)/sum(rain[!is.na(value)])) %>% 
        mutate(saturation = sum_rain * specific_days)
res %>%
    as.data.frame()
#      site year parameter    sum_rain    specific_days saturation
#1  Site_1 2003   param_A 15988875602 0.00000123589041 19760.4980
#2  Site_1 2003   param_B 15988875602 0.00000172552158 27589.1499
#3  Site_1 2003   param_c 15988875602 0.00000002161544   345.6067
#4  Site_1 2004   param_A 15180127505 0.00000116507160 17685.9355
#5  Site_1 2004   param_B 15180127505 0.00000181695952 27581.6772
#6  Site_1 2004   param_c 15180127505 0.00000002185010   331.6873
#7  Site_1 2005   param_A 16058234005 0.00000120130563 19290.8469
#8  Site_1 2005   param_B 16058234005 0.00000186185975 29898.1795
#9  Site_1 2005   param_c 16058234005 0.00000002049335   329.0870
#10 Site_2 2003   param_A  9930134442 0.00000079639249  7908.2845
#11 Site_2 2003   param_B  9930134442 0.00000246576645 24485.3923
#12 Site_2 2003   param_c  9930134442 0.00000003348046   332.4655
#13 Site_2 2004   param_A 10926778631 0.00000088141235  9630.9976
#14 Site_2 2004   param_B 10926778631 0.00000244015257 26663.0070
#15 Site_2 2004   param_c 10926778631 0.00000003448817   376.8447
#16 Site_2 2005   param_A  9599581600 0.00000089477811  8589.4955
#17 Site_2 2005   param_B  9599581600 0.00000238522373 22897.1498
#18 Site_2 2005   param_c  9599581600 0.00000003442887   330.5027
#19 Site_3 2003   param_A 13711985538 0.00000142896664 19593.9700
#20 Site_3 2003   param_B 13711985538 0.00000157700917 21623.9270
#21 Site_3 2003   param_c 13711985538 0.00000004665944   639.7935
#22 Site_3 2004   param_A 14371047715 0.00000134324260 19303.8035
#23 Site_3 2004   param_B 14371047715 0.00000156583784 22502.7303
#24 Site_3 2004   param_c 14371047715 0.00000004859102   698.3039
#25 Site_3 2005   param_A 13729491381 0.00000131305086 18027.5205
#26 Site_3 2005   param_B 13729491381 0.00000159005889 21830.6999
#27 Site_3 2005   param_c 13729491381 0.00000004616979   633.8878





identical(df1['sum_rain'], res['sum_rain'])
#[1] TRUE

identical(df2['specific_days'], res['specific_days'])
#[1] TRUE
library(data.table)
setDT(df)[, .(sum_rain = sum(rain), 
              specific_days = sum(rain*value, na.rm=TRUE)/sum(rain[!is.na(value)])),
            by =  .(site, year= factor(format(date, "%Y")), parameter)
      ][, saturation := sum_rain * specific_days][]
#      site year parameter    sum_rain    specific_days saturation
# 1: Site_1 2003   param_A 15988875602 0.00000123589041 19760.4980
# 2: Site_1 2004   param_A 15180127505 0.00000116507160 17685.9355
# 3: Site_1 2005   param_A 16058234005 0.00000120130563 19290.8469
# 4: Site_1 2003   param_B 15988875602 0.00000172552158 27589.1499
# 5: Site_1 2004   param_B 15180127505 0.00000181695952 27581.6772
# 6: Site_1 2005   param_B 16058234005 0.00000186185975 29898.1795
# 7: Site_1 2003   param_c 15988875602 0.00000002161544   345.6067
# 8: Site_1 2004   param_c 15180127505 0.00000002185010   331.6873
# 9: Site_1 2005   param_c 16058234005 0.00000002049335   329.0870
#10: Site_2 2003   param_A  9930134442 0.00000079639249  7908.2845
#11: Site_2 2004   param_A 10926778631 0.00000088141235  9630.9976
#12: Site_2 2005   param_A  9599581600 0.00000089477811  8589.4955
#13: Site_2 2003   param_B  9930134442 0.00000246576645 24485.3923
#14: Site_2 2004   param_B 10926778631 0.00000244015257 26663.0070
#15: Site_2 2005   param_B  9599581600 0.00000238522373 22897.1498
#16: Site_2 2003   param_c  9930134442 0.00000003348046   332.4655
#17: Site_2 2004   param_c 10926778631 0.00000003448817   376.8447
#18: Site_2 2005   param_c  9599581600 0.00000003442887   330.5027
#19: Site_3 2003   param_A 13711985538 0.00000142896664 19593.9700
#20: Site_3 2004   param_A 14371047715 0.00000134324260 19303.8035
#21: Site_3 2005   param_A 13729491381 0.00000131305086 18027.5205
#22: Site_3 2003   param_B 13711985538 0.00000157700917 21623.9270
#23: Site_3 2004   param_B 14371047715 0.00000156583784 22502.7303
#24: Site_3 2005   param_B 13729491381 0.00000159005889 21830.6999
#25: Site_3 2003   param_c 13711985538 0.00000004665944   639.7935
#26: Site_3 2004   param_c 14371047715 0.00000004859102   698.3039
#27: Site_3 2005   param_c 13729491381 0.00000004616979   633.8878
How to select all records where sum of the amount is equal a value and is grouped by a specific a column (sender or reci

How to select all records where sum of the amount is equal a value and is grouped by a specific a column (sender or reci


By : Song Chang
Date : March 29 2020, 07:55 AM
I wish this help you Source Table: , Here is one method:
code :
select t.*
from sourcetable t
where sender in (select t2.sender
                 from sourcetable t2
                 where t2.datetime >= '2015-05-01' and t2.datetime <= '2016-07-26'
                 group by t2.sender
                 having sum(t2.amount) > 2000
                ) and 
      t.datetime >= '2015-05-01' and t.datetime <= '2016-07-26';
How to copy a select amount of columns with all rows that have a specific number in column A

How to copy a select amount of columns with all rows that have a specific number in column A


By : Àlii Ël Śhaarāŵy
Date : March 29 2020, 07:55 AM
it should still fix some issue I'm trying to copy columns A to E from one sheet that has certain values in Column F. For example I want to copy rows A:E that have a 'X' in column F and paste them to another sheet. , Rewritten as,
code :
With ws.Result.Range ("A1:F" & .Cells(.Rows.Count, "F").End(xlUp).Row)
    ' checks row F to see  whether the number in cell C1 matches any in row F
    .AutoFilter Field := 6, Criteria1 := wsResult.Range("C1") 
    with .resize(.rows.count-1, 5).offset(1, 0)
        If cbool(Application.Subtotal(103, .Cells)) Then
            .SpecialCells(xlCellTypeVisible).Copy Destination:= Main.Range("A22") 
        end if
    end with
end with
MYSQL Select specific amount of duplicate values in column sorted by another column

MYSQL Select specific amount of duplicate values in column sorted by another column


By : Imsunilprabhu
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I'm not sure that I exactly understand the logic of your query, but the following query does at least produce the same result (and surely in significantly less time):
This assumes an index on (user_id, category_id,created_at)
code :
SELECT x.* 
  FROM notes x
  JOIN 
     ( SELECT user_id
            , category_id
            , MAX(created_at) created_at
         FROM notes
        WHERE user_id IN(2)
        GROUP
           BY user_id
            , category_id
     ) y
    ON y.user_id = x.user_id
   AND y.category_id = x.category_id
   AND y.created_at = x.created_at;
SELECT id
     , created_at
     , user_id
     , category_id
  FROM 
     ( SELECT x.*
            , CASE WHEN @prev = category_id THEN @i:=@i+1 ELSE @i:=1 END i
            , @prev := category_id
         FROM notes x
            , (SELECT @prev:=null,@i:=0) vars
        WHERE user_id = 2
        ORDER  
           BY category_id
            , created_at
      ) n
  WHERE i <= 2;
How to select a specific amount of rows before and after predefined values

How to select a specific amount of rows before and after predefined values


By : Patty
Date : March 29 2020, 07:55 AM
should help you out I am trying to select relevant rows from a large time-series data set. The tricky bit is, that the needed rows are before and after certain values in a column. , This is easy enough with rep and its each argument.
code :
df$y[rep(which(df$y == 2), each=7L) + -2:4] <- 2
which(abs(df$y - 2) < 0.001)
Related Posts Related Posts :
  • How to Select record with the maximum value in a GROUP BY?
  • MySQL Innodb Full text Proximity Search Gives Horrible Performance
  • MySQL best approach for db normalising, relationships and foreign keys
  • How to update one table based on the count value of another table while matching ids?
  • MAMP Pro 5.1.1-terminates MySQL when quitting
  • SQL - Get date of most votes cast
  • "Fuzzier" search in mysql
  • Tracing mysqld Using SystemTap
  • SELECT + INSERT + Query Cache = MySQL lock up
  • SQL vs. NoSQL for medium complexity search systems
  • SQL Error when creating table
  • Is it possible to write a query to compare rows to other rows in same table?
  • Display all duplicate records based multiple columns
  • summing time column in mysql
  • InnoDB: Cannot open table
  • Why is IN() considered O(logN) operation?
  • Can a deadlock occur on commit?
  • Is there a fast way to do a '%phrase%' search in any DB?
  • Is using an IN over a huge data set a good idea?
  • How can I know if a table is already arranged in ascending order in MySQL?
  • MySQL - Designing database for a simple game
  • Why am I getting "Host '192.168.1.220' is not allowed to connect to this MySQL server"?
  • what type of password hash? possible mysql hash?
  • MySQL - Using a date range vs functions
  • Using IS NULL and COALESCE in OrderBy Doctrine Querybuilder
  • How to merge MySQL columns into one column if there are empty values in the table?
  • Cardinality Confusion
  • Renaming column multiple ids in SELECT
  • Group all from and to messages per user
  • How to handled the null values in WHERE IN condition in mysql
  • Is it okay to update primary key field to shift a record to the top?
  • Stop query through pdo
  • How to check whether particular value in field in MySQL exists
  • Execute a statement for every table in a database
  • insertion 74G data into mysql table cost more then 2 days, how to improve insert performance
  • Where can I see the differents "Hibernate Console Configurations" in Eclipse
  • MySql | relational database vs non relational database in terms of Performance
  • Exporting mysql database using mysqldump including procedures
  • Trigger MySQL not working
  • How do I update values for individual rows quickly?
  • MySQL join query with multiple where condition
  • MySQL stored procedure is not working
  • MySQL - Order By exact match at the end
  • Select max date or null date from same table MySQL
  • Best solution workaround for needing a mysql event on insert?
  • MySQL select several columns of several tables at the same time without using JOIN
  • Is it more efficient to have a table with one of its columns mostly empty or make a new table and refer to it?
  • mysql data truncated with ñ character
  • MySQL Distinct Active Users for the last month query
  • Get all rows that match another attribute in the same table
  • MySQL statement to get min value with max ID
  • DATEDIFF Current/Date for Last Record
  • What is the logic or procedure for combining multiple DB query's results into one elegant table?
  • Modify TIMESTAMP MySQL for use as Primary Key
  • Django - Efficiently bulk create inherited models
  • MySQL Dual table Join Dual table
  • Ruby on Rails - database where sorted by id
  • MySQL 5.6 : Access denied for user 'root' @ 'localhost' when password contains backslash
  • sql query case dateadd
  • Click on one button multiple times and mySql
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org