Data across multiple years using Sequelize.js - mysql

I am trying to find the month-wise data for multiple years in Sequelize.js
For eg.Stardate:2016-01-01 and EndDate:2017-02-29.
table1
date pack_price
2016-01-01 30
2016-02-19 30
2016-03-14 20
2016-10-01 50
2017-01-28 100
2017-02-25 29
Expected Answer:
date pack_price
Jan 2016 30
Feb 2016 30
Mar 2016 20
Oct 2016 50
Jan 2017 100
Feb 2017 29
Actual Answer
Date Pack_price
Jan 2016 130
Feb 2016 59
Mar 2016 20
Oct 2016 50
Node js code using Sequelize.js
Utils.table1.findAll({
where:{
tran_date: {
[Op.gt]: startTime,
[Op.lt]: endTime
}
},
attributes: [[Sequelize.fn('sum', Sequelize.col('pack_price')),'total'],[Sequelize.fn('month', Sequelize.col('tran_date')),'Month']],
group:[[Sequelize.fn('month', Sequelize.col('tran_date'))]],
raw: true,
}).then(total=>{
Utils.sendResponse(1, total, "success", q)
})
However, this works well for one year.Should work for multiple years.Do you have any idea how I could make this happen?.Thanks in advance.

Related

SQL sum and show row with non-existent sum values

i have 2 tables : dt_user and dt_invoice.
**dt_members :**
id firstname
3 Salim
5 Sara
8 Julie
**dt_invoice**
user_id amount_ht period month year
3 4950 04 2018 04 2018
3 7200 10 2018 10 2018
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
3 8800 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
3 7550 03 2019 03 2019
I want to create a query joining the two table, but i want to show each user_id for PERIOD that there is in table dt_invoice.
**Expected results :**
user_id amount_ht period month year
3 4950 04 2018 04 2018
5 0 04 2018 04 2018 //non-existent record in dt_invoice
8 0 04 2018 04 2018 //non-existent record in dt_invoice
3 7200 10 2018 10 2018
5 0 10 2018 10 2018 //non-existent record in dt_invoice
8 11000 10 2018 10 2018
8 5500 11 2018 11 2018
5 0 11 2018 11 2018 //etc ...
3 6750 11 2018 11 2018
3 8700 12 2018 12 2018
5 0 12 2018 12 2018
8 0 12 2018 12 2018
3 8800 01 2019 01 2019
5 0 01 2019 01 2019
8 7500 01 2019 01 2019
3 4950 02 2019 02 2019
5 0 02 2019 02 2018
8 0 02 2019 02 2018
3 7550 03 2019 03 2019
5 0 03 2019 03 2018
8 0 03 2019 03 2018
Thanks in advance for your help, i'm totally stuck ..
SQL datas available here : https://rextester.com/live/LBSEY76360
also in sqlfiddle : http://sqlfiddle.com/#!9/728af3/1
Use a cross join to generate the rows and left join to bring in the values:
select m.user_id, p.period, p.month, p.year,
coalesce(t.amount_ht, 0) as amount_ht
from dt_members m cross join
(select distinct period, month, year from dt_invoice) p left join
dt_invoice t
on t.user_id = m.id and t.period = p.period;
Maybe this would help.
SELECT user_id, amount_ht, period, month, year
FROM dt_invoice
LEFT JOIN dt_members ON user_id = id

Mysql query for sum data

I want to make a report with MYSQL from this data
Table name: table
date name Quantity
13 Nov Rudy 40
13 Nov Mery 30
13 Nov Rudy 20
13 Nov John 10
14 Nov Rudy 20
14 Nov Rudy 30
I want the result like this
13 Nov Rudy 60
13 Nov Mery 30
13 Nov John 10
14 Nov Rudy 50
What query should I do?
thanks
I'm not sure if mysql has support for 2 columns in group by clause, so grouping by date + user should work. but if it has, you can skip this trick and replace this clause with (group by date name) as #RaymondNijland proposed.
select date, name, sum(quantity) as total
from your_table
group by concat(date, "_", name);

Read the penultimate value ssrs

i have a report with parameter is the year i can select a multiple value
year
Data 2010 2011 2012
hp 14 25 30
Dell 17 18 20
what i need when i create the report i want to have another column with the last value concatenation with the last previous one like this :
year
Data 2010 2011 2012 2012/2011
hp 14 25 30 3025
Dell 17 18 20 2018
i tried this :
=Last(Field!Qte.value)+Last(Field!Qte.value)-1
but i had the wrong result i got this result :
year
Data 2010 2011 2012 2012/2011
hp 14 25 30 3029
Dell 17 18 20 2019
the problem is in this function
Last(Field!Qte.value)-1
it doesn't return the last previous value

adding two column values in mysql

I have two mysql tables
suppose table one name 'marks'
no A B C D
1 10 05 01 04
2 08 07 10 05
3 09 05 07 10
4 07 05 04 10
5 04 07 06 09
6 05 09 07 07
7 09 05 10 06
8 09 06 06 08
9 08 06 10 07
10 08 07 04 06
suppose table two name 'results'
in second table I want to put total marks and average marks based on above table.(import data from 'marks' table,process it and save it in 'results' table)
So once it filled it must be like this.
I want add column A,B,C,D in 'marks' table and put total value in column 'Total' in table 'results' and average by dividing 'Total' column by 4.
no Total Average
1 20 5.00
2 30 7.50
3 31 7.75
4 26 6.50
5 26 6.50
6 28 7.00
7 30 7.50
8 29 7.25
9 31 7.75
10 25 6.25
So how can I fill the 'result' table using mysql query?
Is it possible to do in mysql?
Thank you
Try something like:
INSERT INTO result (no, total, average)
SELECT no, A+B+C+D, (A+B+C+D)/4
FROM marks

RDLC report, generate a Pivot chart

I have the following data table format generated from SQL. Users can select which car models to be populated in the graph. There will be different number of Car models appearing in different reports. So there will be variable number of line charts appearing in the graph.(One line for one car model series)
Jan Feb Mar Apr May Jun
Honda 12 17 24 18 30 13
Toyota 15 20 10 15 30 40
Yamaha 30 25 30 15 13 40
Suzuki 35 15 13 40 45 45
Nissan 15 35 40 40 50 50
Kia 13 21 23 15 25 30
Mazda 25 25 30 32 15 40
How can I create a graph like this with RDLC reports?
This can be easily done using series groups in rdlc charting. The chart data source should be structured like this.
Brand Month Value
Honda Jan 10
Honda Feb 15
Honda Mar 20
Toyota Jan 20
Toyota Feb 21
Toyota Mar 22
Yamaha Jan 10
Yamaha Feb 11
Yamaha Mar 12
Add "Value" column as chart Values.
Add "Month" column as chart Categories.
Add "Brand" column as chartSeries Groups.