August 22, 2015 at 12:27 pm
total L is 11 and Total R is 1 count all node
August 22, 2015 at 9:32 pm
Snce you're new here, here's how to post your data so that people here can help. Here's your data...
use tempdb;
GO
CREATE TABLE Data (
ID INT NOT NULL,
JoiningDate DATE,
Placement CHAR(1),
pID INT,
cID INT,
referBy INT);
GO
INSERT INTO Data(ID, joiningDate, placement,pID, cID, referBy)
VALUES (4,'2015-02-02','L',4,5,4),
(6,'2015-02-02','R',5,8,4),
(8,'2015-02-02','R',4,11,4),
(9,'2015-02-02','L',5,10,4),
(25,'2015-12-12','L',8,9,4),
(31,'2015-08-21','R',8,12,4),
(33,'2015-08-21','R',12,13,4),
(36,'2015-08-21','R',9,14,4),
(37,'2015-08-21','M',9,15,4),
(38,'2015-08-21','L',10,16,4),
(39,'2015-08-21','M',4,17,4);
Given that, could you please provide the answer that should be returned by the query you're working on? (And perhaps an explanation of the rules to get there?)
Thanks!
Pieter
August 22, 2015 at 10:48 pm
your question is not clear
could you please give some more detail ?
August 22, 2015 at 11:50 pm
August 23, 2015 at 4:55 am
There is a neat technique where you sum a case with a counter to get this kind of information.
SELECT SUM(CASE WHEN placement = 'L' THEN 1 ELSE 0 END) AS LeftCount,
SELECT SUM(CASE WHEN placement = 'R' THEN 1 ELSE 0 END) AS RightCount,
SELECT SUM(CASE WHEN placement NOT IN('L','R') THEN 1 ELSE 0 END) AS ExceptionCount,
count(*) as TotalCount
FROM MyTable
Lowell
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply