| Author |
Topic |
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-03-30 : 14:24:25
|
| select au_lname, au_fname,au_idfrom authors where 100 =all (select royaltyper from titleauthor where titleauthor.au_id = authors.au_id)This query uses database pubs. Why this code returns some au_id which is not in table titleauthor?for example 527-72-3246 is not in titleauthor.how to find the names of all authors who earn 100 percent royalty on all his/her books?Thanks=================================================au_lname au_fname au_idBlotchet-Halls Reginald 648-92-1872Carson Cheryl 238-95-7766del Castillo Innes 712-45-1867Greene Morningstar 527-72-3246Locksley Charlene 486-29-1786McBadden Heather 893-72-1158Panteley Sylvia 807-91-6654Smith Meander 341-22-1782Straight Dean 274-80-9391Stringer Dirk 724-08-9931White Johnson 172-32-1176 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-03-30 : 14:56:04
|
| THX,The purpose of this query is to find the names of all authors who earn 100 percent royalty on all his/her booksJeff |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-30 : 15:20:52
|
| Yes, and where is the ROYALTY information?Even if two people cowrite a book, nothing says they share it equal, 50-50 percent!Rephrase your question.Do you want all authors who are single authors of a book?Peter LarssonHelsingborg, Sweden |
 |
|
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-03-30 : 15:37:23
|
| tabale authorsau_id au_lname au_fname172-32-1176 White Johnson213-46-8915 Green Marjorie238-95-7766 Carson Cheryl267-41-2394 O'Leary Michael274-80-9391 Straight Dean341-22-1782 Smith Meander409-56-7008 Bennet Abraham427-17-2319 Dull Ann472-27-2349 Gringlesby Burt486-29-1786 Locksley Charlene527-72-3246 Greene Morningstar648-92-1872 Blotchet-Halls Reginald672-71-3249 Yokomoto Akiko712-45-1867 del Castillo Innes722-51-5454 DeFrance Michel724-08-9931 Stringer Dirk724-80-9391 MacFeather Stearns756-30-7391 Karsen Livia807-91-6654 Panteley Sylvia846-92-7186 Hunter Sheryl893-72-1158 McBadden Heather899-46-2035 Ringer Anne998-72-3567 Ringer AlbertTable titleauthorau_id title_id au_ord royaltyper172-32-1176 PS3333 1 100213-46-8915 BU1032 2 40213-46-8915 BU2075 1 100238-95-7766 PC1035 1 100267-41-2394 BU1111 2 40267-41-2394 TC7777 2 30274-80-9391 BU7832 1 100409-56-7008 BU1032 1 60427-17-2319 PC8888 1 50472-27-2349 TC7777 3 30486-29-1786 PC9999 1 100486-29-1786 PS7777 1 100648-92-1872 TC4203 1 100672-71-3249 TC7777 1 40712-45-1867 MC2222 1 100722-51-5454 MC3021 1 75724-80-9391 BU1111 1 60724-80-9391 PS1372 2 25756-30-7391 PS1372 1 75807-91-6654 TC3218 1 100846-92-7186 PC8888 2 50899-46-2035 MC3021 2 25899-46-2035 PS2091 2 50998-72-3567 PS2091 1 50998-72-3567 PS2106 1 100I want find the name of find the names of all authors who have royaltyper=100 for all his/her booksthe result should look likeau_lname au_fname au_idWhite Johnson 172-32-1176Green Marjorie 213-46-8915Carson Cheryl 238-95-7766Straight Dean 274-80-9391Blotchet-Halls Reginald 648-92-1872del Castillo Innes 712-45-1867Panteley Sylvia 807-91-6654I want 486-29-1786 becauase both of his book has royaltyper=100I do not want Ringer Albert 998-72-3567becase one of his books has royaltyper=50Thnaks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-30 : 15:57:18
|
| [code]SELECT a.au_lname, a.au_fname, a.au_idFROM Authors AS aINNER JOIN TitleAuthor AS t ON t.au_id = a.au_idGROUP BY a.au_lname, a.au_fname, a.au_idHAVING MIN(t.royaltyper) = 100ORDER BY a.au_id[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-30 : 16:25:23
|
This can be an alternative, especially if the TitleAuthor table has records like267-41-2394 PS2092 2 50267-41-2394 PS2092 1 50 By mistake an author is registered twice or more for a single book, but is still single author.SELECT a.au_lname, a.au_fname, a.au_idFROM ( SELECT au_id, title_id, SUM(royaltyper) AS royalty FROM @TitleAuthor GROUP BY au_id, title_id ) AS xINNER JOIN @Authors AS a ON a.au_id = x.au_idGROUP BY a.au_lname, a.au_fname, a.au_idHAVING MIN(royalty) = 100ORDER BY a.au_id Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-04-02 : 14:50:18
|
| Peter,Thank you for all help. I am a guy in finance field, SQL is hard for me. I usally need to spend quite long to figure out how your code work. And I can figure out some. I benefit a lot from this forum.Jeff. |
 |
|
|
|