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. Please assist me in combining these sql queries

Please assist me in combining these sql queries

Scheduled Pinned Locked Moved Database
databasehelpsalesquestion
1 Posts 1 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.
  • P Offline
    P Offline
    paul4everyone
    wrote on last edited by
    #1

    Greetings to you, Please assist me in combining these sql queries I have some record in my database (sql ce 4.0), using; 1.

    Select Customer_ID as Customer, Credit, Debit, Transaction_Date as Date
    from ThriftsTrans Where Transaction_Date Between '15/Dec/2013' And '18/Dec/2013'

    Produces this result;

    Customer Credit Debit Date

    000001 12000 2013-12-16T14:32:00.9770000
    000001 5000 2013-12-16T14:32:26.0070000
    000001 2000 2013-12-16T14:32:43.3870000
    000001 2000 2013-12-17T10:23:08.6470000
    000002 50000 2013-12-17T10:25:35.4730000
    000002 1000 2013-12-17T10:25:49.4230000
    000002 3000 2013-12-17T10:26:07.4800000

    If i run this; 2.

    Select Customer_ID as Customer, sum(Credit) as Credit, sum(Debit) as Debit,
    (Sum(Credit)-Sum(Debit)) as Balance, (count(Credit) + count(Debit)) as Count
    from ThriftsTrans Where Transaction_Date Between '15/Dec/2013' And '18/Dec/2013' Group By Customer_ID

    I will get;

    Customer Credit Debit Count

    000001 19000 2000 4
    000002 51000 3000 3

    and lastly if i run; 3.

    Select Customer_ID as Customer, Account_Balance as Balance, Transaction_Date as Date From ThriftsTrans Where Transaction_Date In (Select Max(Transaction_Date) From ThriftsTrans Where Transaction_Date
    Between '15/Dec/2013' And '18/Dec/2013' Group By Customer_ID)

    I will get;

    Customer Balance Date

    000001 17000 2013-12-17T10:23:08.6470000
    000002 48000 2013-12-17T10:26:07.4800000

    But my problem now, is how do i combine query 2 & query 3 to get the following output from my database;

    Customer Credit Debit Count Balance Date

    000001 19000 2000 4 17000 2013-12-17T10:23:08.6470000
    000002 51000 3000 3 48000 2013-12-17T10:26:07.4800000

    Please help me and thanks a lot in advance.

    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