Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I am developing a Query using some requirements
in select statement i am giving Number,date,department,Type etc..Also I am summing up sum(sales) in select statement.. I need to add the below two conditions in my query. How to implement it in SQL statement.
Condition :
1) total amount(sales) with TYPE = s equals zero
2)total amount(sales) with TYPE = y is less than zero
sample code :
Select Number,sum(sales) as Total_Sales, Type, Date, Department
from ...// pulled necessary table//
where....// date condition and link fields are given here//
groupby Number,sales, Type, Date, Department;
can you please suggest.
Select a.*
from (Select Number,sum(sales) as Total_Sales, Type, Date, Department
from ...// pulled necessary table//
where....// date condition and link fields are given here//
group by Number,sales, Type, Date, Department )a
Where (a.Total_Sales=0 and Type='s') or (a.Total_Sales<0 and Type='y')
I think a Preceding Load statement would work.
sample code :
Load *
where (Total_Sales = 0 and TYPE = 's') or (Total_Sales < 0 and TYPE = 'y');
SQL Select Number,sum(sales) as Total_Sales, Type, Date, Department
from ...// pulled necessary table//
where....// date condition and link fields are given here//
groupby Number,sales, Type, Date, Department;
Select a.*
from (Select Number,sum(sales) as Total_Sales, Type, Date, Department
from ...// pulled necessary table//
where....// date condition and link fields are given here//
group by Number,sales, Type, Date, Department )a
Where (a.Total_Sales=0 and Type='s') or (a.Total_Sales<0 and Type='y')
Thanks a lot