iphone - Using Multiple Tables, Multiple Values with Min() SQL -


I am using SQLite in an application that I am developing.
I have a very complex query (complicated for me!) And I need basic results, but I'm stuck in finishing the last obstacle.

I have no work for this question yet which I have to do ...

SELECT SUM (ACTIVITY) ACTIVITY with activities where activity_ID (selection by name) The name of the food group name_id is named SUM (points)> 20);

I need to add another part in this query, but this is where something has become complicated for me. There are three tables ... dates, food, activities and I have to find out the amount of a result group, in which there is a minimum number between two different values ​​from two different tables, unless a certain statement is true.

Actually ..

  from SELECT SUM (total) (SELECT MIN (value from table1, which is defined by value in Table 2, value from Table 3) Total Table 3 Table 3 contains the result set from Table 1);  

The query below is something I came with, if there is no syntax (Qualified!). It does not work, but I want to understand it better what I am trying to do. (SELECT MIN (SELECT SUM (points) - 20 items where name_id IN (name = id) by SELECT SUM (activity_amount), name_id by group), activity) Activity_amount activities as activity from WHERE activity_id IN (name_id name group with name id) and name_id HAVING SUM (points)> 20);

The problem is with the first value in the MIN () ....

  SELECT SUM (points) - 20 Food where name_id IN (Weekly = 1 from SELECT pk date) GROUP BY name_id  

This statement creates more than one value, but even if I compare it to others compared to those values Requires MIN () , I only need one at a time ... not as a complete set.

How can I get something like the above mentioned query to work?

Edit ... For some examples, some example tables, thanks to Jellommannky and Hinsteck Table # 1 (date) create tables (PK Integer Primary Key, Date Integer, Weekly Integer) PK Date Weekly 1 05062009 1 2 05072009 1 3 05082009 2 Table # 2 Table Foods (PK Integer Primary Key, Food VARCHAR (64), Double Digits, Name ID IIDEGER) PK Food Points name_id 1 Food 1 12.0 1 2 Food 2 9.0 1 3 meals 3 5.0 1 4 Jan 4 15.0 2 5 Meals 5 14.0 2 6 Meals 6 12.0 3 Table # 3 (Activities) Create table activities (PK Integer Primary key, activity repeat, activity_id integer) PK activity activity_id 1 5.0 1 2 4.0 1 3 2.0 2 4 4.0 With 3 and

query from the previous post and my original post (which does not work), I would like to set one set with a value ..8.0

MIN (26.0-20, 9.0) = 6.0
MIN (29.0-20, 2.0) = 2.0 - 6.0 + 2.0 = 8.0

I hope it helps!

After very head-scratched and divining, I suspect that you may want to: Join name foods from SEPT SUM (MIN (fp-20, AP)) from FP Date (SELECT dates.pk AS FD, SM) to name name = Join FD Group FP (FP & gt; = 20) by F.G. (SELECT dates.pk AS AD, SM (Activity) Date of ARF activity_ID = Ad Group advertising) FD = VI The name of the campaign P> appears to have zero connection with their meaning, but hey, at least this gives 8.0 and the sub-selections give those other numbers which you mention !) -


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -