473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

get day records based on id

hi,

am using query as
Expand|Select|Wrap|Line Numbers
  1. 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,

Expand|Select|Wrap|Line Numbers
  1. string rdate = dateTimePicker1.Value.ToString("yyyy-MM-dd");
Expand|Select|Wrap|Line Numbers
  1. MachineID Name Quantity BilledAmount ReceivedAmount
  2. V0001 petrol 61 244 244
  3. V0002 Diesel 186 726 726
  4. V0002 petrol 155 605 605
  5. Total 402 1575 1575
But i want for every machine id ,total row

Expand|Select|Wrap|Line Numbers
  1. V0001 - - - -
  2. total - - -
  3. V0001 - - - -
  4. total - - -
Mar 14 '14 #1
4 1053
Luuk
1,047 Expert 1GB
"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'
Mar 14 '14 #2
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,machine_id
Mar 14 '14 #3
above out put is after the querying database.
i want output as

V0001 Petrol - - -
Diesel - - -
Total - - -
V0002 Petrol - - -
Diesel - - -
total - - -
Mar 14 '14 #4
Luuk
1,047 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. select 
  2.     MachineID, 
  3.     Name, 
  4.     Quantity, 
  5.     BilledAmount, 
  6.     ReceivedAmount 
  7. from (
  8.     Select 1, 
  9.         machine_id as MachineID,
  10.         item_name as Name,
  11.         SUM(item_quantity) as Quantity,
  12.         SUM(billed_amount) as BilledAmount,
  13.         SUM(received_amount) as ReceivedAmount 
  14.     from transaction 
  15.     where DATE(paid_date)='" + rdate + "' 
  16.     Group by machine_id,item_name
  17. union 
  18.     Select 2, 
  19.         machine_id as MachineID,
  20.         '' as Name,SUM(item_quantity) as Quantity,
  21.         SUM(billed_amount) as BilledAmount,
  22.         SUM(received_amount) as ReceivedAmount 
  23.     from transaction 
  24.     where DATE(paid_date)='" + rdate + "' 
  25.     Group by machine_id
  26. order by MachineID, 1)
  27.  
Mar 14 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SomeDude | last post by:
Lo group, I would like to know if it is possible to a (string) replace on existing records based on a given pattern. Let's say I have a table containing the following records (strings):...
11
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in...
1
by: arthur-e | last post by:
How can you select records based on more than one combo box - I have a combobox that selects records based on name (I'm sure this has been asked a thousand times - web site answer/link could be...
0
by: lj | last post by:
How do I get an asp.net datagrid to set certain records as tedittemplate based on a certain condition. It is for a simple workflow. The user will have permission to see a list of records. He...
1
by: AA Arens | last post by:
I have a form with navigation button and they brows through the records. How to change the order or the way these records are navigated? Like before based on ID, now I want based on another field,...
4
by: Eugene Anthony | last post by:
I have a table that has a DateTime column which uses a DataTime datatype. How do I retrieve a range of records based on the month and year using ms sql? Eugene Anthony *** Sent via...
6
by: BEETHOVEN | last post by:
I have an option group called Issue_Type on my main form F1_Member_Demographics_Main. When I select one of the 3 options on the main form from the option group Issue_Type I want to limit the sub...
8
by: cehlinger | last post by:
I am trying to add multiple records based on a date range. I found some examples and have tried them but am getting errors and I can't seem to figure out what the problem is. I am not a VBA...
12
by: lev9shun | last post by:
Hi all, I have a reporting table that I use for my reports but would like to filter(flag) records based certain Medical conditions. Example of reporting table: ID Name MedCond Reported...
3
by: Yoni Hasid | last post by:
Hello, I am struggling with finding a solution on how to assign numerical values to text records based on various criteria. I have a table with survey responses where each column has text records...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.