×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help with SQL - I get column with 0 for each record

Help with SQL - I get column with 0 for each record

Help with SQL - I get column with 0 for each record

(OP)
Hi guys
1º lemme explain situation:
there're clients who buy at a shop. there're promotions in shop (can be normal or special). one promotion says: "for each u$s 100 you buy, you get 1 point". client can exchange points by gifts.

2º Take a look at this image

http://img24.echo.cx/img24/2770/errorsql19dy.jpg

some terms translated:

CLIENTE.NOMBRE = CLIENT.NAME
FACTURACION.PUNTOS = PURCHASE.POINTSOBTAINED
FACTURACION.MONTO = PURCHASE.AMMOUNTOFMONEY
CANJE.TOTALPUNTOS = EXCHANGE.TOTALPOINTS
espromoesp = ISPROMOTIONESPECIAL
PUNTOS_RESTANTES = TOTALPOINTS_LEFT
PUNTOS_CANJEADOS = POINTS_EXCHANGED
CLIENTE.IDPROMO = CLIENTE.IDPROMOTION

**************************************************
**************************************************

does any1 know why i get 0 in PUNTOS_RESTANTES ?
I should get this difference:

PURCHASE.POINTSOBTAINED - EXCHANGE.TOTALPOINTS

I mean, the points client got in all purchases made
minus all the points he exchanged

**************************************************
**************************************************

If there's yet something you don't understand (it is in spanish) please tell me...

THANKS A LOT FOR YOUR HELP

RE: Help with SQL - I get column with 0 for each record

Try to change the GROUP BY clause into:
GROUP BY 1,2

RE: Help with SQL - I get column with 0 for each record

(OP)
GROUP BY 1,2 ?

I get syntax error...

Anyway, I'm getting same result if I change the order of "appearance" in the group by clause...

any ideas ? thanks a lot 4 helping..

the SQL engine I use is www.nexusdb.com and it is compatible with ISO SQL standards, etc.

RE: Help with SQL - I get column with 0 for each record

You can group by ordinal position but probably nexusdb doesn't accept this syntax. I did a mistake, anyway, indicating that. Because looking again on your query I saw that your second term in the GROUP BY clause is an aggregate function. You cannot do such thing. And I'm pretty sure that PUNTOS_RESTANTES is a field in your database  which explains the results.

RE: Help with SQL - I get column with 0 for each record

(OP)
No...

PUNTOS_RESTANTES is not a field in my DB, this is a field in the query...

"... SUM(FACTURACION.PUNTOS) - SUM(CANJE.TOTALPUNTOS) AS PUNTOS_RESTANTES, ..."

I had to put PUNTOS_RESTANTES in group by clause because i get error if i do not do so... :(

Note:
I also replaced SUM(FACTURACION.PUNTOS) by 10000 to see if the query was substracting, but instead 0 i got 10000 for each record...

After this, i replaced SUM(CANJE.TOTALPUNTOS) by 1000 and i got -1000 in each record...

So, it seems nexus is not taking this values... none of them....

I'm becoming nuts with this... Thanks a lot 4 helping !!

RE: Help with SQL - I get column with 0 for each record

Look again at the GROUP BY syntax, but as far I know, you cannot use an aggregate function in a GROUP BY clause.
At least this is what is said in the SQL syntax language for Firebird 1.5 which is pretty close to the ANSI92 standard.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close