Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I have 3 tables like
TAB_1
ID
NUMBER
1
101
2
102
3
103
4
104
5
105
6
106
7
107
8
108
9
109
10
110
TAB_2
ID
NUMBER
1
101
2
102
3
105
TAB_3
ID
NUMBER
1
104
2
107
3
110
The output needs to be:
ID
NUMBER
1
103
2
106
3
108
4
109
I think u can use NOT IN with Subqueries
Like;
SELECT
*
FROM
Table_1
WHERE
Number NOT IN (Select number from Table_2) and
Number NOT IN (Select number from Table_3)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 12 days ago.
Improve this question
Is there a way I can get previous SKU data in present row in SQL Server:
Date
Fol
SKU
Amount
01-01-2021
44
1
2
01-01-2021
44
2
3
05-03-2021
45
1
4
05-03-2021
45
2
5
08-06-2021
46
1
6
08-06-2021
46
2
7
13-08-2021
47
1
8
13-08-2021
47
2
9
Expected
Date
Fol
SKU
Amount
Previous Amount
01-01-2021
44
1
2
---------
05-03-2021
45
1
4
2
08-06-2021
46
1
6
4
13-08-2021
47
1
8
6
01-01-2021
44
2
3
---
05-03-2021
45
2
5
3
08-06-2021
46
2
7
5
13-08-2021
47
2
9
7
I've tried lag function but it's not resulting as expected
Date
Fol
SKU
Amount
Previous Amount
01-01-2021
44
1
2
---------
01-01-2021
44
2
3
2
05-03-2021
45
1
4
3
05-03-2021
45
2
5
4
08-06-2021
46
1
6
5
08-06-2021
46
2
7
6
13-08-2021
47
1
8
7
13-08-2021
47
2
9
8
Thanks!
The window functions are well worth your time to get comfortable with them
Select *
,PrevAmt = lag(AMOUNT,1) over (partition by SKU order by date)
From YourTable
Results
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I feel like I'm not understanding how to do the syntax for this.
SELECT
main_category,
COUNT(main_category) AS 'Kickstarters',
CAST(SUM(if(state = 'successful', 1, 0)) AS SIGNED) AS 'Successful_Kickstarters'
FROM
projects
GROUP BY
main_category;
Results:
Music 127 63
Film & Video 170 68
Theater 20 13
Art 86 41
Design 66 29
Publishing 79 24
Photography 29 12
Technology 63 24
Dance 9 6
Fashion 52 18
Food 60 22
Games 85 40
Journalism 9 4
Crafts 17 4
Comics 33 17
My problem is that I want to figure out the biggest number within these columns, but I don't know how to refer to them from within the query.
Maybe this?
SELECT main_category
,MAX(Kickstarters)
,MAX(Sucessful_Kickstarters)
,MAX(if(Kickstarters > Sucessful_Kickstarters, Kickstarters, Sucessful_Kickstarters))
FROM
(
SELECT main_category
,COUNT(main_category) AS 'Kickstarters'
,CAST(SUM(if(state = 'successful', 1, 0 ) )AS SIGNED) AS 'Sucessful_Kickstarters'
FROM projects
GROUP BY main_category
) DS
GROUP BY main_category
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Let's suppose and EMP_Table consists of following columns
EMPID,SAL,DEPTID,MGRID
Req: List all managers whose salary is > all of team members salary
Sample Input:
EmpID SAL DEPTID MGRID
101 10000 A 102
102 30000 A 102
103 15000 A 102
104 10000 B 106
105 30000 B 106
106 45000 B 106
107 50000 B 106
108 20000 C 109
109 50000 C 109
110 45000 C 109
Expected output:
EmpID SAL DEPTID MGRID
102 30000 A 102
109 50000 C 109
SELECT M.EmpID, M.Salary, M.DepId, M.MgrId
FROM dbo.Employee E INNER JOIN
dbo.Employee M ON
E.EmpID = M.MgrId
WHERE E.Salary >= (SELECT MAX(DE.Salary) FROM dbo.Employee DE WHERE DE.DepId = E.DepId)
AND M.Salary >= E.Salary
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I Have following table which contains details of Employee
EmpId EmpName Mgr Salary Dept
1 Deepak 2 20000 1
2 Annu NULL 22000 1
3 Jai 2 19500 1
4 Jitendra 1 18000 2
5 Vaishali 1 18000 2
6 Philip 4 15000 3
I wants to show salary of each dept with each employee details,if it repeats no issues as shown below
EmpId EmpName Mgr Salary Dept DeptSal
1 Deepak 2 20000 1 61500
2 Annu NULL 22000 1 61500
3 Jai 2 19500 1 61500
4 Jitendra 1 18000 2 36000
5 Vaishali 1 18000 2 36000
6 Philip 4 15000 3 15000
You should look into the SUM() OVER(PARTITION) windowing functions in SQL Server.
See this MSDN link
This link should help you in solving your problem.
If you are still compelled to get a solution rather than understanding how you can solve these type of problems, then answer is mentioned in a single line as spoiler below
select *, DeptSal=sum(Salary) over (partition by Dept ) from t
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
BILL_NO COUTER TRANTYPE BARCODE DES TRANAMT
164 1 V 21021 ALOKOZAY TISSUE 150S (3.50)
164 1 s 21021 210521 CABAGE 5.00
164 1 C CASH CASH 1.50
208 2 V 120110 NATCO ORANGE MARMALA (6.75)
208 2 S 120110 NATCO ORANGE MARMALA 6.75
208 2 C CASH CASH -
164 3 S 5404568 FRESH FISH 18.00
164 3 S 5406464 ARYAA IDLY/DOSA MIX 5.00
164 3 S 654954 DETTOL SENSITIVE 125 7.00
164 3 C CASH CASH 30.00
i want select bill no from my table where trantype='v'
but i need result as metioned below thank you
BILL_NO COUTER TRANTYPE BARCODE DES TRANAMT
164 1 V 21021 ALOKOZAY TISSUE 150S (3.50)
164 1 s 21021 210521 CABAGE 5.00
164 1 C CASH CASH 1.50
208 2 V 120110 NATCO ORANGE MARMALA (6.75)
208 2 S 120110 NATCO ORANGE MARMALA 6.75
It's not entirely clear to me, but I think you want something like this:
select t1.*
from the_table t1
where exists (select 42
from the_table t2
where t2.bill_no = t1.bill_no
and t2.trantype = 'V'
and t2.couter = t1.couter);
That would return bill_no = 208 and trantype = 'C' as well (which is not part of your example output). But as you didn't explain that missing row it's hard to write a proper solution.
Assuming the missing row for Bill_no 208 is just a typo, the following solution might help:
WITH cte AS
(
SELECT BILL_NO, COUNTER
FROM YourTable WHERE TRANTYPE ='V'
)
SELECT yt.*
FROM YourTable yt
INNER JOIN cte ON yt.BILL_NO = cte.BILL_NO AND yt.COUNTER=cte.COUNTER