Source is Sales Table:
Sno Prod Sales Sales_Amount
1 A 10 2000
2 A 20 1000
3 C 10 3000
4 D 30 4000
5 A 20 1000
Target :
Sales_Count T_Sales_Amt Sales_Count(A) T_Sales_Amt(A)
90 11000 50 4000
In single query, pls tell me.
Answers were Sorted based on User's Feedback
Answer / shailesh j
select sum(sales) as Sales_Count,sum(sales_amount) as
T_Sales_Amt,SUM(DECODE(PROD,'A',SALES,0)) as
Sales_Count_A,SUM(DECODE(PROD,'A',SALES_AMOUNT,0))
T_Sales_Amt_A from sales;
Is This Answer Correct ? | 11 Yes | 0 No |
Answer / vishalakshi
select
tab1.sales_count,tab1.t_sales_amt ,tab2.sales_count_A,tab2.t
_sales_amt_A
From
(select sum(sales) sales_count,sum(sales_amount)
t_sales_amt from sales)tab1,
(select sum(sales) sales_count_A,sum(sales_amount)
t_sales_amt_A from sales where prod='A' group by prod)tab2
Is This Answer Correct ? | 8 Yes | 1 No |
Answer / satish
select sum(prod),
sum(sales_amount),
sum(decode(prod,'A',sales)),
sum(decode(prod,'A',sales_amount))
from sales
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / welcomeashwin
SELECT
T1.SALES_COUNT, T1.T_SALES_AMT,
T2.SALES_COUNT_A, T2.T_SALES_AMT_A
FROM
(SELECT SUM(SALES) SALES_COUNT,
SUM(SALES_AMOUNT) T_SALES_AMT
FROM SALES)T1,
(SELECT SUM(SALES) SALES_COUNT_A,
SUM(SALES_AMOUNT) T_SALES_AMT_A
FROM SALES
WHERE PROD='A' GROUP BY PROD)T2
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ravi
select sum(sales) sales_count,sum(sales_amount) t_sales_amount
,(select sum(sales_count) sales_count(A),sum(sales_amount)
t_sales_amt(A) from sales_table group by prod) from sales_table;
Is This Answer Correct ? | 0 Yes | 4 No |
What is coalesce in sql?
How to find last day of the month in sql query
How to assign sql query results to pl sql variables?
C. Normalize the following data up to the 3rd Normal form. Create the tables and insert the data given. Emp_ID Name Dept_Name Salary Course_Title Date_Completed 100 Adam Marketing 48,000 SPSS 6/19/2008 Surveys 10/7/2008 140 Bob Accounting 52,000 Tax Acc 12/8/2008 110 Cathy IT SQL Server 1/12/2008 C# 4/22/2008 190 Dan Finance 150 Emily Marketing 55,000 SPSS 6/16/2008 42,000 Analysis 8/12/2008 Queries 1. Find all Names who have completed the SPSS Course. 2. Find employee with max salary. 3. Find employee with 2nd max salary. 4. Find all employees in Dept “Marketing”. 5. Find all the employees who have taken more than 2 courses. 6. Find all the employees who have completed the courses before month of September.
how to drop an existing view in mysql? : Sql dba
explain the difference between delete , truncate and drop commands? : Sql dba
how to concatenate two character strings? : Sql dba
What is asqueryable?
How does a covering index work?
How to read xml file in oracle pl sql?
What is dbo in sql?
Name the operator which is used in the query for pattern matching?