Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. get the difference of two attributes in two tables

get the difference of two attributes in two tables

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    00thilani
    wrote on last edited by
    #1

    I have a table called "Issue" and table called "Receive" and both have same attributes they are "code,curr_val,date,coin_note,no_of_items,amount,operator_id,officer_id"And also code ,curr_val, and date are superkeys. data types are char(8),datetime,char(1)if t is a coin c,if it is a note n,money,char(8),char(8) I'm using sql server 2000 I want to get the difference of currency values (ex no of $10notes,$50 notes).In other words I want to get the difference of Items in the "no_of items"attribute. I tried toget notes value and no of notes items in receive table. >SELECT curr_val,count(*)AS Items ,SUM (amount)AS Amount_Rs FROM RECEIVE AS R WHERE coin_note='n'GrOUP BY curr_val I tried toget notes values and no of notes items in issue table >SELECT curr_val,count(*)AS Items ,SUM (amount)AS Amount_Rs FROM ISSUE AS I WHERE coin_note='n'GrOUP BY curr_val . What I want is the difference betveen the items values of R and I with their currency value please help ASAP Thanx Thilani

    C 1 Reply Last reply
    0
    • 0 00thilani

      I have a table called "Issue" and table called "Receive" and both have same attributes they are "code,curr_val,date,coin_note,no_of_items,amount,operator_id,officer_id"And also code ,curr_val, and date are superkeys. data types are char(8),datetime,char(1)if t is a coin c,if it is a note n,money,char(8),char(8) I'm using sql server 2000 I want to get the difference of currency values (ex no of $10notes,$50 notes).In other words I want to get the difference of Items in the "no_of items"attribute. I tried toget notes value and no of notes items in receive table. >SELECT curr_val,count(*)AS Items ,SUM (amount)AS Amount_Rs FROM RECEIVE AS R WHERE coin_note='n'GrOUP BY curr_val I tried toget notes values and no of notes items in issue table >SELECT curr_val,count(*)AS Items ,SUM (amount)AS Amount_Rs FROM ISSUE AS I WHERE coin_note='n'GrOUP BY curr_val . What I want is the difference betveen the items values of R and I with their currency value please help ASAP Thanx Thilani

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      00thilani wrote:

      both have same attributes

      Attributes? Do you mean "columns"?

      00thilani wrote:

      superkeys

      I am unfamiliar with that term. Do you mean "primary key"? Or perhaps "foreign key"? Perhaps this will work:

      SELECT
      curr_val,
      Items_Rs - Items_Is AS items_difference,
      Amount_Rs - Amount_Is AS difference_amount
      FROM (
      SELECT curr_val, count(*) AS Items_Rs, SUM(amount) AS Amount_Rs
      FROM RECEIVE
      WHERE coin_note='n'
      GROUP BY curr_val
      ) AS Received
      INNER JOIN (
      SELECT curr_val, count(*) AS Items_Is, SUM(amount) AS Amount_Is
      FROM ISSUE
      WHERE coin_note='n'
      GROUP BY curr_val
      ) AS Issued
      ON Issued.curr_val = Received.curr_val


      Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups