But I'm trying to find it by the country. So I want to return the highest rated wine from Canada and Mexico and China at the same time with no extras. I'm not allowed to list the second lowest below.
The Big Programming Thread - Page 382
| Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
|
obesechicken13
United States10467 Posts
But I'm trying to find it by the country. So I want to return the highest rated wine from Canada and Mexico and China at the same time with no extras. I'm not allowed to list the second lowest below. | ||
|
WolfintheSheep
Canada14127 Posts
On October 27 2013 13:47 obesechicken13 wrote: Having some difficulty with database homework problems. I'm trying to find a highest average rating for something (let's assume movies, but it's really wine). But I'm trying to find it by the country. So I want to return the highest rated wine from Canada and Mexico and China at the same time with no extras. I'm not allowed to list the second lowest below. Is this supposed to be in SQL? If so, it should be fairly easy if you look through the API. Depending on how the database is setup, and the constraints on the question, you might have to do some annoying JOINs and have a very bloated query. | ||
|
obesechicken13
United States10467 Posts
On October 27 2013 14:08 WolfintheSheep wrote: Is this supposed to be in SQL? If so, it should be fairly easy if you look through the API. Depending on how the database is setup, and the constraints on the question, you might have to do some annoying JOINs and have a very bloated query. Yeah, I think I'm getting it. Very bloated indeed but it forces me to use some of the stuff in class. Here's something that's messing me up. I need to be able to get only the avg_rate column in order to do a comparison and find a max value. Unless having allows you to compare on a single element and not a grouping like where does (brb have to try this) ![]() This query returns fine ![]() Why is everything 0s? I'm running postgresql latest in a gui environment and the gui compiler seems a bit buggy (I can't use doublequotes) so maybe that's the problem. Figured out an alternative: drop view relation2 cascade; create view relation2 as (select wmname, cname, avg(rating) as avg_rate from countries c2 natural join wine w2 natural join winemakers wm2 natural join ratings r2 group by wmname, cname); create view relation3 as( select cname,max(avg_rate) from relation2 group by cname); select relation2.cname, relation2.wmname, avg_rate from relation2 natural join relation3 where relation2.cname=relation3.cname and relation2.avg_rate=relation3.max; Basically I made 2 views and compared them to each other using where. | ||
|
teamamerica
United States958 Posts
On October 27 2013 14:37 obesechicken13 wrote: Yeah, I think I'm getting it. Very bloated indeed but it forces me to use some of the stuff in class. Here's something that's messing me up. I need to be able to get only the avg_rate column in order to do a comparison and find a max value. Unless having allows you to compare on a single element and not a grouping like where does (brb have to try this) ![]() This query returns fine ![]() Why is everything 0s? I'm running postgresql latest in a gui environment and the gui compiler seems a bit buggy (I can't use doublequotes) so maybe that's the problem. I can't speak to why your query is failing but it doesn't seem like the query is doing what you want. I'm assuming this because a cid (5) is listed twice. Afaik, when you group by more then one column, it will group by the tuple of columns you selected; it won't group by one column then the other. So grouping by (wname, cid) groups collapses all the rows where the (wname, cid) match, which does not limit it to one per country. A better example of this is: http://stackoverflow.com/questions/2421388/using-group-by-on-multiple-columns If you want the wine with the highest average rating in every country, I think the query you want is:
Although someone here might be able to point out a better solution. One thing I personally prefer is to use explicit joins rather than natural so you know what columns you're joining on. But that's just my limited exp. As for HAVING vs WHERE - HAVING lets you act on aggregate values. You can use HAVING avg_count > 5; while without using a subquery, you cannot do that with where. i.e
is the same as
| ||
|
obesechicken13
United States10467 Posts
On October 27 2013 16:21 teamamerica wrote: I can't speak to why your query is failing but it doesn't seem like the query is doing what you want. I'm assuming this because a cid (5) is listed twice. Afaik, when you group by more then one column, it will group by the tuple of columns you selected; it won't group by one column then the other. So grouping by (wname, cid) groups collapses all the rows where the (wname, cid) match, which does not limit it to one per country. A better example of this is: http://stackoverflow.com/questions/2421388/using-group-by-on-multiple-columns I read that post. The reason it doesn't work for me is that I needed the max of the average by country. It's a funny twist. Anyways, thank you. That would have pointed me in the right direction and definitely, explicit > implicit. | ||
|
teamamerica
United States958 Posts
| ||
|
obesechicken13
United States10467 Posts
On October 27 2013 16:36 teamamerica wrote: Oh ok, so the ratings table also mentions contains the country the rating was filed from? I should have asked for the schema before I did anything! I should have provided the schema. It turns out I made some mistakes when doing natural join too. I natural joined two tables with no common attributes ![]() I don't think it caused any problems though. The reasons the 0s showed up was that my GUI was just being dumb. When it shows a number, it converts to a real (double or float) So the integer number 12 is converted to 12.000000000000000000000000000000000 Rather than show me the 12.000000000000000000000000000000000 it shows me the latter half 12.000000000000000000000000000000000 | ||
|
pyro19
6575 Posts
I've been tasked with making a 4 bit Processor and I'm stuck :/ | ||
|
icystorage
Jollibee19350 Posts
On October 27 2013 21:18 pyro19 wrote: Does anyone know any good websites for Learning VHDL? I've been tasked with making a 4 bit Processor and I'm stuck :/ http://www.nand2tetris.org/ i learned HDL here by following its course ![]() | ||
|
Shield
Bulgaria4824 Posts
I know how to handle button events but I'd like to have an internal 2D int array to represent the puzzle. In other words, if a user clicks the image at row 2, column 1; that's ok, The only problem is I don't know how to associate the image at that location with an int array[1][0] (in this case). I hope I was clear. Any ideas? I like this implementation more than TextFields because it's more user friendly imho. | ||
|
bangsholt
Denmark138 Posts
| ||
|
Shield
Bulgaria4824 Posts
On October 28 2013 09:20 bangsholt wrote: You make an array of labels, initialize with an ImageIcon in the GUI and then you have a direct translation of the indices. Means you can even use the same buttonhandler if you do it correctly. Does the label need to be visible though? I'd not like that. ![]() Edit: One more question. Is the recursive method faster in this case? I'm trying to print a 2D array in this case but I'll need to do rows and columns checking later, so I'm wondering which approach to take. I usually know that iteration is preferred, but what if the recursive method is just O(n)? Iterative, it should be O(n^2).
Recursive, it should be... O(n)? And more memory consuming too?
| ||
|
delHospital
Poland261 Posts
On October 29 2013 04:40 darkness wrote: + Show Spoiler + On October 28 2013 09:20 bangsholt wrote: You make an array of labels, initialize with an ImageIcon in the GUI and then you have a direct translation of the indices. Means you can even use the same buttonhandler if you do it correctly. Does the label need to be visible though? I'd not like that. ![]() Edit: One more question. Is the recursive method faster in this case? I'm trying to print a 2D array in this case but I'll need to do rows and columns checking later, so I'm wondering which approach to take. I usually know that iteration is preferred, but what if the recursive method is just O(n)? Iterative, it should be O(n^2).
Recursive, it should be... O(n)? And more memory consuming too?
Let's say your array has n rows and m columns. You want to print all the cells, that's m*n numbers that you want to print. You can't do that faster than O(n*m) ![]() | ||
|
Shield
Bulgaria4824 Posts
On October 29 2013 09:26 delHospital wrote: Let's say your array has n rows and m columns. You want to print all the cells, that's m*n numbers that you want to print. You can't do that faster than O(n*m) ![]() So basically, O(n^2) is the fastest you can get with a 2D array if I understood right. What about those 1D arrays that act like 2D? Are they still O(n^2)? They should be I guess. ![]() | ||
|
Zocat
Germany2229 Posts
Short version: If you have a 1D array where you have n*m elements it's still O(n^2). 1D / 2D arrays mean shit. You can have a 1D array representing O(n^n). To you initial question: Parameter for button click. HashTable (dictionary, ...) maps the parameter to 2D array. | ||
|
bangsholt
Denmark138 Posts
On October 29 2013 04:40 darkness wrote: Does the label need to be visible though? I'd not like that. ![]() <snip> The label is initialized with an image rather than text. This will make it a picture. Hence the "initialize with an ImageIcon". There's probably other ways too, this is just the Swing way I could remember. | ||
|
Shield
Bulgaria4824 Posts
On October 30 2013 03:09 bangsholt wrote: The label is initialized with an image rather than text. This will make it a picture. Hence the "initialize with an ImageIcon". There's probably other ways too, this is just the Swing way I could remember. So, from what I've understood, it is: ImageIcon ii = new ImageIcon("some.jpg"); JLabel label = new JLabel(ii); How do I know which index (e.g. int array[3][4]) this image represents? Yup, you said an array but I'm just trying to figure it out for a single label for now. I expected some kind of info like: label.getText() which may return "3,4" or something, except this text is not shown on GUI. Edit: Do I just use label.setName("3,4") and label.getName()? | ||
|
bangsholt
Denmark138 Posts
Once you have the source of the event you can change the label to whatever you want - a new picture as an example - you *do* need to search through the "whole" array to find it though, but it's so small it doesn't matter anyway. | ||
|
pebble444
Italy2499 Posts
I am trying to build a website. My goal is to have a place with different pages, upload different kind of files like audio content, pictures, make it downloadable, make it available in Both English and Italian; I don' t want to have a blog. I want to have it custom, with an entry page. Now, for now i have secured a domain name. My question is this: where should i go from here? what type of web hosting should i be looking at? what is a reasonable price; I am willing to put time into doing this and learn something. I used to have fun with Html, very basic things like links, images, fonts; is learning more Html enough to build a website from zero? or should i just try and use some template i find? I am a little confused as to where to start/go from here, any advice i would greatly appreciate | ||
|
Shield
Bulgaria4824 Posts
On October 30 2013 22:49 pebble444 wrote: Hello friends, i need some advice: I am trying to build a website. My goal is to have a place with different pages, upload different kind of files like audio content, pictures, make it downloadable, make it available in Both English and Italian; I don' t want to have a blog. I want to have it custom, with an entry page. Now, for now i have secured a domain name. My question is this: where should i go from here? what type of web hosting should i be looking at? what is a reasonable price; I am willing to put time into doing this and learn something. I used to have fun with Html, very basic things like links, images, fonts; is learning more Html enough to build a website from zero? or should i just try and use some template i find? I am a little confused as to where to start/go from here, any advice i would greatly appreciate I'm in no way experienced with web programming but it sounds me that you need PHP if you are looking for dynamic page content. There are other scripting languages too. JavaScript can't hurt if you compliment it with php/html too. There is a platform called Joomla if you don't want to start from scratch. Link: http://www.joomla.org/ | ||
| ||
![[image loading]](http://i.imgur.com/8iYrf6j.png)
![[image loading]](http://i.imgur.com/0SNlPRT.png)


;