colombo
colombo

Reputation: 520

Multiple Select Statements for count

I have a one table called data.It has few columns as i mentioned below.What i need to do is i want to get count for attributes in those columns.right now i am getting count for those attributes.but the same time it print other columns as well.i have attach an image. from that just i want product and total columns.also like that i want Courier and Total in another view..what should i do?enter image description here

Here is my code

SELECT Product, Courier, Acc_No, Name, Delivered_Date, 
    Month, Bill_Run, Status, Remarks, count(id) as Total  
FROM data 
    WHERE ID = ID
    [AND Product = "{pro_id,false}"]
    [AND Courier = "{cou_id,false}"]
    [AND Bill_Run = "{bill_id,false}"]
    [AND Dispatch_Type = "{dis_id,false}"]
    [AND Status = "{sta_id,false}"]
    [AND Acc_No = "{acc_no,false}"]
    [AND Name = "{name,false}"]
    [AND Delivered_Date between {date_range,RANGE1} and {date_range,RANGE2}] 
    ORDER BY ID ASC

Upvotes: 0

Views: 55

Answers (1)

Saqib Amin
Saqib Amin

Reputation: 1171

For First One:

SELECT Product,
       count(id) AS Total
FROM DATA
WHERE ID = ID [AND Product = "{pro_id,false}"][
  AND Courier = "{cou_id,false}"][
  AND Bill_Run = "{bill_id,false}"][
  AND Dispatch_Type = "{dis_id,false}"][
  AND Status = "{sta_id,false}"][
  AND Acc_No = "{acc_no,false}"][
  AND Name = "{name,false}"][
  AND Delivered_Date BETWEEN {date_range,
                              RANGE1} AND {date_range,
                                           RANGE2}]
ORDER BY ID ASC

For Second View:

SELECT Courier,
       count(id) AS Total
FROM DATA
WHERE ID = ID [AND Product = "{pro_id,false}"][
  AND Courier = "{cou_id,false}"][
  AND Bill_Run = "{bill_id,false}"][
  AND Dispatch_Type = "{dis_id,false}"][
  AND Status = "{sta_id,false}"][
  AND Acc_No = "{acc_no,false}"][
  AND Name = "{name,false}"][
  AND Delivered_Date BETWEEN {date_range,
                              RANGE1} AND {date_range,
                                           RANGE2}]
ORDER BY ID ASC

Upvotes: 1

Related Questions