473,407 Members | 2,598 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,407 software developers and data experts.

SQL Query to sum accross the row

Hi,

Can someone help to write a query that will sum the information across the row, not down the column.

nome_item Sunday Monday Tuesday Wednesday Thursday Friday Total
item1 12 5 5 9 4 23 58
item2 2 6 2 2 45 3 60
item3 3 7 3 3 4 3 23
item4 4 8 4 4 4 5 29
Sep 17 '07 #1
4 28805
azimmer
200 Expert 100+
Hi,

Can someone help to write a query that will sum the information across the row, not down the column.

nome_item Sunday Monday Tuesday Wednesday Thursday Friday Total
item1 12 5 5 9 4 23 58
item2 2 6 2 2 45 3 60
item3 3 7 3 3 4 3 23
item4 4 8 4 4 4 5 29
You just add up the columns like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT nome_item, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, 
  2. Sunday+Monday+Tuesday+Wednesday+Thursday+Friday as Total
  3. FROM mytable
  4.  
  5.  
Sep 17 '07 #2
You just add up the columns like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT nome_item, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, 
  2. Sunday+Monday+Tuesday+Wednesday+Thursday+Friday as Total
  3. FROM mytable
  4.  
  5.  
------------------------------------------------------------------------------------------------------------

I run the query, but it's the results of the Total column is '0'.

Do you have any idea?
Sep 17 '07 #3
azimmer
200 Expert 100+
------------------------------------------------------------------------------------------------------------

I run the query, but it's the results of the Total column is '0'.

Do you have any idea?
It works fine (I tried) so long as your days columns are of numeric type (i.e. int). If they are string (char, varchar -- why?), you need to cast them like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT nome_item, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, 
  2. cast(Sunday as int)+...+cast(Friday as int) as Total
  3. FROM mytable
  4.  
Sep 17 '07 #4
It works fine (I tried) so long as your days columns are of numeric type (i.e. int). If they are string (char, varchar -- why?), you need to cast them like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT nome_item, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, 
  2. cast(Sunday as int)+...+cast(Friday as int) as Total
  3. FROM mytable
  4.  
__________________________________________________ ________

Thanks!!!

This works very fine!!
Sep 18 '07 #5

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

Similar topics

2
by: Jochem | last post by:
Hello, Lately I came accross this problem a couple of times, and I know there must be a clever solution. However, I did not find it untill now. When I add a entry to my mysql database from a...
1
by: Paul Hallam | last post by:
How does oracle distribute records in a table that is in a tablespace with multiple datafiles. Very simplisticly Ingres will distribute sequential records evenly across multiple datafiles for a...
0
by: iffriganovitch | last post by:
Hello, My records contain a position, from 1 to n. This position is not the primary key. In normal conditions, the position of this records should be as follows: 1, 2, 3, 4, 5, 6, 7, 8, 9...
0
by: Conner | last post by:
Hi Bob, I know this reply is a little late for you but I just came accross your post. You might be interested to know that there is a pretty good query tool available on download.com called...
3
by: Jeff | last post by:
Access 97 I have three single digit feilds and would like to query on only two of them however, the data is accross all three fields. Exsample: Query for 34 would return: 340 304
9
by: Christine | last post by:
It has come to my attention that sometimes, when I open a Query in SQL View, the SQL that I see is not exactly the same as the SQL in the Query's Querydef. The difference I see (only occasionally)...
4
by: Hans | last post by:
Hi, I want to allow users to start my application only once. To do so, I use Process Processes = Process.GetProcessesByName("MyApp"); to get all processes running on the machine and compair...
3
by: sar68 | last post by:
I'm using Access 2007 on windows vista. Intel T7400 with 2.16 GHz and 2 gigs of ram. 64 bit os. If I run a query that goes across multiple tables, I get sensible results. However, if I run a...
4
by: cephal0n | last post by:
Hi everyone! I've been studying SELECT INTO in vba and made my own. I was successful in generating my own table, strSql = "SELECT * INTO tblTemp49 FROM qryUnq49" conn.Execute strSql now I...
45
by: dizzydangler | last post by:
Hi, I'm new to access (2007, running on XP), but I've gotten some great help from this site on my project so far. However, the more I know, the more complex the problems seem to become.... I'm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.