get day records based on id

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajeswari02
    New Member
    • Nov 2013
    • 8

    #1

    get day records based on id

    hi,

    am using query as
    Code:
    Select machine_id as MachineID,item_name as Name,SUM(item_quantity) as Quantity,SUM(billed_amount) as BilledAmount,SUM(received_amount) as ReceivedAmount from transaction where DATE(paid_date)='" + rdate + "'Group by machine_id,item_name
    here rdate , am collecting from UI,

    Code:
    string rdate = dateTimePicker1.Value.ToString("yyyy-MM-dd");
    Code:
    MachineID Name Quantity BilledAmount ReceivedAmount
    V0001 petrol 61 244 244
    V0002 Diesel 186 726 726
    V0002 petrol 155 605 605
    Total 402 1575 1575
    But i want for every machine id ,total row

    Code:
    V0001 - - - -
    total - - -
    V0001 - - - -
    total - - -
    Last edited by Rabbit; Mar 14 '14, 03:36 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    "But i want for every machine id ,total row"

    than you should GROUP, and SUM() things in your query, not on 'machine_id' and 'item_name' but only on 'machine_id'

    Comment

    • rajeswari02
      New Member
      • Nov 2013
      • 8

      #3
      Based on item_name also actually
      i am having records with name"petrol" more than 1 per day , so i need to sum() based on item_name,machi ne_id

      Comment

      • rajeswari02
        New Member
        • Nov 2013
        • 8

        #4
        above out put is after the querying database.
        i want output as

        V0001 Petrol - - -
        Diesel - - -
        Total - - -
        V0002 Petrol - - -
        Diesel - - -
        total - - -

        Comment

        • Luuk
          Recognized Expert Top Contributor
          • Mar 2012
          • 1043

          #5
          Code:
          select 
          	MachineID, 
          	Name, 
          	Quantity, 
          	BilledAmount, 
          	ReceivedAmount 
          from (
          	Select 1, 
          		machine_id as MachineID,
          		item_name as Name,
          		SUM(item_quantity) as Quantity,
          		SUM(billed_amount) as BilledAmount,
          		SUM(received_amount) as ReceivedAmount 
          	from transaction 
          	where DATE(paid_date)='" + rdate + "' 
          	Group by machine_id,item_name
          union 
          	Select 2, 
          		machine_id as MachineID,
          		'' as Name,SUM(item_quantity) as Quantity,
          		SUM(billed_amount) as BilledAmount,
          		SUM(received_amount) as ReceivedAmount 
          	from transaction 
          	where DATE(paid_date)='" + rdate + "' 
          	Group by machine_id
          order by MachineID, 1)

          Comment

          Working...