I am newbie, I am very confused how to do sum query. Here is my query :
and this is an output from my query :
all i want is Sum my presentase field by month..
i already created sum query, but all i gonna got by my query just error code :((( ..
here my sum query :
SUM(IF( YEAR(PO_HARI) = 2016, PRESENTASE_SATUAN, 0)) AS TOTAL_JANUARY
and also i added TOTAL_JANUARY On my group_by but didnt work.
thank you for attention .
try this
select year(po_date) yeardate, month(po_date) monthdate,
sum(case Point_del
when 1 then 25
when 2 then 50
when 3 then 75
when 4 then 100
else 0
) TOTAL_JANUARY
from jbox2_po..POT01A
where month(po_date)=1
group by year(po_date) , month(po_date)
you can add 'and year(po_date)=2016' into clause where if you want only 2016 year
IF youre using sql server management studio then try this :::
select sum(presentase) from tablename
group by month(PO_HARI)
--here i am assuming that "presentase" is a summable field and 'po_hari' is a date column
Related
I'm wondering if there's a way or an expression I could use in SSRS to show a Yes or No based on a Distinct Count function?
Example of what I'm currently using - RM_Name is the group
=CountDistinct(iif(Fields!qtrtradecnt.Value >= 15, 1, Nothing), "RM_Name")
I also would like to show if the qtrtradecnt is >= 15 to show a Y or N based on the RM_Name group, and maybe countdistinct is not the correct function to use...I've messed with this for days.
Thank you!
One way to do this is to the calculation in your your dataset.. with a case expression..
select
...
,case when your_table.qtrtradecnt >= 15 then 1 else 0 end as rm_count
from your_table
Then in your report just do a
=iif(sum(Fields!rm_count.value) >15 then 'Y','N')
Can you help me to make the sum of all the values of the "Total_Profit" row that is in partition 1 of my database.
select
Total_Profit,
$partition.FUNCIONDEPARTICION2(Order_Priority)
from
cliente
where
$partition.FUNCIONDEPARTICION2(Order_Priority) = 1
In this query I already show all the values but I don't know how to add them
Just use SUM():
select SUM(Total_Profit)
from cliente
where $partition.FUNCIONDEPARTICION2(Order_Priority) = 1
I just joined after having a problem writing a query in MS Access. I am trying to write a query that will pull out the first two valid samples in from a list of replicated sample results and then would like to average the sample values. I have written a query that does pull samples with only two valid samples and averages these values. However, my query doesn't pull samples where there are more than two valid sample results. Here's my query:
SELECT temp_platevalid_table.samp_name AS samp_name, avg (temp_platevalid_table.mean_conc) AS fin_avg, count(temp_platevalid_table.samp_valid) AS sample_count
FROM Temp_PlateValid_table
WHERE (Temp_PlateValid_table.id In (SELECT TOP 2 S.id
FROM Temp_PlateValid_table as S
WHERE S.samp_name = S.samp_name and s.samp_valid=1 and S.samp_valid=1
ORDER BY ID))
GROUP BY Temp_PlateValid_table.samp_name
HAVING ((Count(Temp_PlateValid_table.samp_valid))=2)
ORDER BY Temp_PlateValid_table.samp_name;
Here's an example of what I'm trying to do:
ID Samp_Name Samp_Valid Mean_Conc
1 54d2d2 1 15
2 54d2d2 1 20
3 54d2d2 1 25
The average mean_conc should be 17.5, however, with my current query, I wouldn't receive a value at all for 54d2d2. Is there a way to tweak my query so that I get a value for samples that have more than two valid values? Please note that I'm using MS Access, so I don't think I can use fancier SQL code (partition by, etc.).
Thanks in advance for your help!
Is this what you want?
select pv.samp_name, avg(pv.value_conc)
from Temp_PlateValid_table pv
where pv.samp_valid = 1 and
pv.id in (select top 2 id
from Temp_PlateValid_table as pv2
where pv2.samp_name = pv.samp_name and pv2.samp_valid = 1
)
group by pv.samp_name;
You might need avg(pv.value_conc * 1.0).
There is a similar question which answer this for a known number of columns and only a single selection column. But the problem here is that
I have no knowledge of columns (count, type) of a specified SQL query and also I want to blank for all columns not a single column.
For example lets say I have following query.
Select * from View1
Result :
Column(1) Column(2) Column(..) Column(N)
1 A Sales 1500
2 C Sales 2500
3 C Sales 2500
4 A Development 2500
Expected result :
Column(1) Column(2) Column(..) Column(N)
1 A Sales 1500
2 C 2500
3
4 A Development
Pseudo SQL Query :
EXEC proc_blank_query_result 'Select * from View1'
If you're in SQL Server 2012 or newer, you can do this with lag, something like this:
select
nullif(column1, lag(column1) over (order by yourorderbyclause)) as column1,
nullif(column2, lag(column2) over (order by yourorderbyclause)) as column2,
...
from
View1
To make it dynamic, well then you have to parse a lot of metadata from the query. Using sp_describe_first_result_set might be a good idea, or use select into a temp. table and parse the columns of it.
I am working with SQL Language.
I have a table named parta. I want to count the fields 40b1 and 40b2 and find the sum of this. My query is here.
select
count(40b1) as 40b1,
count(40b2) as 40b2,
sum(count(40b1) + count(40b2) ) as sum,
code/100 as code
from parta
where 40b1=true and mandays>=1000
group by code/100 ;
Expected output
40b1 40b2 sum code verticalsum
5 5 10 20 7
2 2 4 21 7
How it done? Please help.
For getting this verticalsum column, what query can I use?
You don't need to SUM() the COUNT()'s. Just add them together.
select count(40b1) as 40b1,
count(40b2) as 40b2,
count(40b1) + count(40b2) as sum,
code/100 as code
from parta
where 40b1=true and mandays>=1000
group by code/100 ;