Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:24:38+00:00 2026-06-11T22:24:38+00:00

I have got a problem with an SQLite select. There are the tables kategorie,lv,majetok,parcela.

  • 0

I have got a problem with an SQLite select.

There are the tables “kategorie”,”lv”,”majetok”,”parcela”.

Each person has information about what he owns in the table “majetok”. The sample record:

id      idpodfk idlvfk  podiel  podield cislozlv datum1         datum2
1       31      1       1/10000 0,0001  789      16. 9. 2012    16. 9. 2012

idpodfk-fk of person id
idlvfk-fk of land record id

There is also table LV (table of land records), sample record:

idlv    lvnazov katuzemie
1       1830    Plavecký Mikuláš

Also I use the table “parcela”, I store in there information about parcels in the land record

pnazov  rozloha idlvfk  idkategoriafk typ
5432    692312  1       1             C

And table kategorie

idkategoria  meno 
1            Lesné pozemky

What I need:
a foreach record in this select

SELECT   SUM(podield) AS sum1, idlvfk
FROM     majetok a
WHERE    idpodfk = 1
GROUP BY idlvfk

I need to select this

SELECT     SUM(par.rozloha)*sum1 AS m2, kat.meno --sum1 from statement above
FROM       Parcela par 
INNER JOIN kategorie kat ON par.IDkategoriaFK = kat.IDkategoria
WHERE      par.IDLVFK = 1 --IDLVFK from statement above
GROUP BY   kat.meno

The (second’s) query output should look like this

m2     kat.meno
123.23 Lesne pozemky    --FOR FIRST IDLVFK
324.52 Ostatne pozemky  --FOR FIRST IDLVFK   
235    Pasienky         --FOR FIRST IDLVFK 
144.23 Lesne pozemky    --FOR NEXT IDLVFK
543.52 Ostatne pozemky  --FOR NEXT IDLVFK
756    Pasienky         --FOR NEXT IDLVFK
.
.
.

And then I need to group by kat.meno so the final output should look like this:

m2     kat.meno
267,46 Lesne pozemky
868,04 Ostatne pozemky
991    Pasienky
.                         --other kat.meno if there is
.                         --other kat.meno if there is

Is this possible in one query or do I need to process it on a front-end?

Tables and query background:

There are some parcels in land record (every parcel has its own category, eg forest parcel etc). Person owns a part of a land record (saved in table majetok, eg: 1/1000). That mean he owns 1/1000 from each parcel in that land record. I want to select the area (column “rozloha” in parcela table) that he owns for each category (SUM(par.rozloha)*sum1 AS m2). So we must count sum of all parcels in that category on that land record and multiply with part that owns that person. But he can own 1/1000 on one land record and 3/3456 on the second land record (another land record=another parcels) so we have to do for each land record and that summarize you can see in last code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:24:39+00:00Added an answer on June 11, 2026 at 10:24 pm

    A join over all four tables would not have the correct number of records for the sums.

    What you can do is to use subqueries in place of views:

    SELECT SUM(step2.area_sum),
           step2.meno
    FROM (SELECT SUM(rozloha) * sum(podield_sum) AS area_sum,
                 par.idlvfk,
                 meno
          FROM parcela par
          JOIN kategorie kat ON par.idkategoriafk = kat.idkategoria
          JOIN (SELECT SUM(podield) AS podield_sum,
                       idlvfk
                FROM majetok
                GROUP BY idlvfk) AS ps ON ps.idlvfk = par.idlvfk
          GROUP BY idlvfk,
                   meno) AS step2
    GROUP BY step2.meno
    

    I’ve tested with example data on SQL Fiddle: http://sqlfiddle.com/#!2/626e6/9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a strange problem about in_array recently which I cannot understand. e.g.
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
I have got very big problem because I would like to get more information
I have got a problem to get back a parameter from my view to
I have got a problem with calling a global function, which takes a pointer
I have got a the following problem: I have got multi-step form where in
The problem is: I have got a table of columns (A, B, C) where
I have problem with context menu. I have got: @Override public void onCreateContextMenu(ContextMenu menu,
have a nice day. I got problem when trying to create an image from
I'm getting crazy with this problem: I have got some Oracle SQL-Reports to redesign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.