Click here to Skip to main content
15,881,709 members
Home / Discussions / Database
   

Database

 
QuestionQuery Response Time - SQL Server Replication Pin
JammoD8714-Jun-15 1:48
JammoD8714-Jun-15 1:48 
AnswerRe: Query Response Time - SQL Server Replication Pin
Mycroft Holmes14-Jun-15 13:03
professionalMycroft Holmes14-Jun-15 13:03 
AnswerRe: Query Response Time - SQL Server Replication Pin
GuyThiebaut14-Jun-15 21:25
professionalGuyThiebaut14-Jun-15 21:25 
AnswerRe: Query Response Time - SQL Server Replication Pin
Tim Carmichael15-Jun-15 9:06
Tim Carmichael15-Jun-15 9:06 
AnswerRe: Query Response Time - SQL Server Replication Pin
JammoD8716-Jun-15 1:16
JammoD8716-Jun-15 1:16 
QuestionDatabase grouping of rows using values into columns Pin
indian14310-Jun-15 8:48
indian14310-Jun-15 8:48 
AnswerRe: Database grouping of rows using values into columns Pin
Richard Deeming10-Jun-15 9:05
mveRichard Deeming10-Jun-15 9:05 
AnswerRe: Database grouping of rows using values into columns Pin
Eddy Vluggen10-Jun-15 9:29
professionalEddy Vluggen10-Jun-15 9:29 
SQL
CREATE TABLE Class
(
    Id   BIGINT PRIMARY KEY
   ,Name VARCHAR(50)
)
INSERT INTO Class (Id, Name) VALUES (1, '7th Class')
INSERT INTO Class (Id, Name) VALUES (2, '8th Class')
INSERT INTO Class (Id, Name) VALUES (4, '10th Class')
CREATE TABLE Marks
(
    StudentId BIGINT,
    ClassId BIGINT,
    Marks BIGINT
)
INSERT INTO Marks (StudentId, ClassId, Marks) VALUES (1, 1, 35)
INSERT INTO Marks (StudentId, ClassId, Marks) VALUES (2, 1, 90)
INSERT INTO Marks (StudentId, ClassId, Marks) VALUES (3, 2, 75)
INSERT INTO Marks (StudentId, ClassId, Marks) VALUES (4, 2, 30)
Try something like
SQL
SELECT c.Name,
      (SELECT COUNT( * ) FROM Marks WHERE ClassId = c.Id AND Marks >= 50) AS [Passed],
      (SELECT COUNT( * ) FROM Marks WHERE ClassId = c.Id AND Marks < 50) AS [Failed]
  FROM Class c
If you try the query here[^], you'll not just see the actual result, but also get timings and a nice execution plan.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

QuestionCompare Database Projects Pin
Ashfaque Hussain7-Jun-15 19:47
Ashfaque Hussain7-Jun-15 19:47 
AnswerRe: Compare Database Projects Pin
Mycroft Holmes7-Jun-15 19:54
professionalMycroft Holmes7-Jun-15 19:54 
GeneralRe: Compare Database Projects Pin
Ashfaque Hussain7-Jun-15 20:06
Ashfaque Hussain7-Jun-15 20:06 
QuestionDB2 Please Help Here Pin
ganeshbdas7-Jun-15 2:23
ganeshbdas7-Jun-15 2:23 
AnswerRe: DB2 Please Help Here Pin
CHill608-Jun-15 22:25
mveCHill608-Jun-15 22:25 
AnswerRe: DB2 Please Help Here Pin
CHill6017-Jun-15 1:50
mveCHill6017-Jun-15 1:50 
QuestionSeparating names from a single column to 2 columns Pin
jkirkerx6-Jun-15 7:59
professionaljkirkerx6-Jun-15 7:59 
AnswerRe: Separating names from a single column to 2 columns Pin
Kornfeld Eliyahu Peter6-Jun-15 22:16
professionalKornfeld Eliyahu Peter6-Jun-15 22:16 
GeneralRe: Separating names from a single column to 2 columns Pin
jkirkerx7-Jun-15 7:11
professionaljkirkerx7-Jun-15 7:11 
GeneralRe: Separating names from a single column to 2 columns Pin
Kornfeld Eliyahu Peter7-Jun-15 9:56
professionalKornfeld Eliyahu Peter7-Jun-15 9:56 
QuestionHow to restore a DB with DATA and Schema generated through script ? Pin
Azam Niaz Ch.6-Jun-15 2:52
Azam Niaz Ch.6-Jun-15 2:52 
AnswerRe: How to restore a DB with DATA and Schema generated through script ? Pin
Eddy Vluggen6-Jun-15 5:13
professionalEddy Vluggen6-Jun-15 5:13 
GeneralRe: How to restore a DB with DATA and Schema generated through script ? Pin
Azam Niaz Ch.6-Jun-15 21:48
Azam Niaz Ch.6-Jun-15 21:48 
GeneralRe: How to restore a DB with DATA and Schema generated through script ? Pin
Eddy Vluggen7-Jun-15 0:19
professionalEddy Vluggen7-Jun-15 0:19 
Questionpossible to get results of 3 different tables in 1 set of column results? Pin
jkirkerx5-Jun-15 17:50
professionaljkirkerx5-Jun-15 17:50 
AnswerRe: possible to get results of 3 different tables in 1 set of column results? Pin
Mycroft Holmes5-Jun-15 23:12
professionalMycroft Holmes5-Jun-15 23:12 
GeneralRe: possible to get results of 3 different tables in 1 set of column results? Pin
jkirkerx6-Jun-15 7:51
professionaljkirkerx6-Jun-15 7:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.