If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > can't solve one query!! please help, tricky one

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-02-09, 06:41
mpasha mpasha is offline
Registered User
 
Join Date: Sep 2009
Posts: 2
can't solve one query!! please help, tricky one

helo... i have a problem with some tables and getting data from them... hope some one can help me...


ok i have two table

TABLE A:
-id
-product_number
-costs

TABLE B:
-id
-product_number
-typ_of_product


the two product_number are the same...

now the idea si this:

i need to get all the typ_of_product which made in TABLE A most costs ORDERED BY DESC and GROUPED BY typ_of_product

the problem is the product_numer 's are uniqe but they belong to some typ and i can't order and group them by typ looking how much costs they make

hope someone can help me, because i am thinking for hours now and can't get the right query for this...
Reply With Quote
  #2 (permalink)  
Old 09-02-09, 08:05
mpasha mpasha is offline
Registered User
 
Join Date: Sep 2009
Posts: 2
solved

ok i have solved it thanks anyway:

CREATE VIEW temporary AS SELECT `produkt_numer` as numer, `typ_of_product` as typ,`costs` as s
FROM `tableA` , `tableB`
WHERE `tableA.product_number` = `tableB.produkt_number`;

select count(numer) as howmuch, typ from temporary group by typ order by homuch desc;
Reply With Quote
  #3 (permalink)  
Old 09-02-09, 09:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
i'm glad you solved it, but i should like to point out that ...

1) `tableA.product_number` and `tableB.produkt_number` are invalid (you can't put backticks around the qualified columns like that)

2) you don't actually need a view
Code:
SELECT COUNT(*) AS howmuch
     , typ 
  FROM ( SELECT tableA.product_number AS numer
              , tableB.typ_of_product AS typ
              , tableA.costs AS s
           FROM tableA 
         INNER
           JOIN tableB
             ON tableB.produkt_number = tableA.product_number
       ) AS temporary 
GROUP 
    BY typ 
ORDER
    BY homuch DESC
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On