I constructed a query which might return results faster, but it has all these nasty subqueries.
Is there a better way to write this?
SELECT * FROM
(
SELECT *,
(
SELECT SUM( weight ) FROM table t2 WHERE t2.id <= t1.id
) AS sum_weight
FROM table t1
) AS t3...
Thanks Tony!!!
That SQL significantly dropped the load on the server...
I'm not sure why (it still has the dreaded "ORDER BY RAND()" in there), but it's working great!!!
thanks againg for all your help.
jeff
Thanks Rudy and Tony!
I'll try both methods, but I think any SQL statement with the "ORDER BY RAND()" clause in it will have poor performance... but I'm no guru, it's just what I've read.
Thanks again for your help!!!
Jeff
Tony,
Yes you are correct!!! I want more probability of the higher-weighted records returned.
Again, the above query works probability wise, it just gets slower and slower as the table grows.
Does anyone know how to re-write this? Help!!!
Thanks,
Jeff
I'm trying to retrieve a "random" row from a table where the randomness is "weighted" by a factor, let's call it "weight" (original, huh?).
the following (pseude-SQL) works but is EXTREMELY slow:
SELECT * FROM table
ORDER BY RAND() * ( 1 / weight)
LIMIT 1;
I've read that "ORDER BY RAND()"...
Tony,
Thanks for your help!
That looks like it might work, but I can can't get MySQL to evaluate the sub-select. It gives me a syntax error #1064 (I'm using phpMyAdmin to run the query) as follows:
MySQL said:
#1064 - You have an error in your SQL syntax. Check the manual that...
Sorry for all the questions guys! I'm a SQL newb...
I have 2 tables I'm trying to join:
traits
trait_num trait_name trait_value
1 color blue
2 color red
3 color green
4 size small
5 size medium
6 size...
This query I'm trying to construct seems simple, but I can't get it to work. Can someone please help?!?!?!
I have two tables...
My "products_to_traits" table has the following data:
product_num trait_num
1 1
1 12
1 23
1 30
2 1
2 30
2...
thanks for your help!
if the table is named "categories," do you mean:
select a.category_value
from categories as a
join categories as b using ( product_id )
where b.category_value = 'engineering'
if so, i'll try that and report back.
thanks again!
good question! sorry i wasn't clear to start. i want only values that all widgets with a red value have (i think!).
another example from the data would be: if i selected "engineering," i would want to return "black," "red," "square," and "round," since widget1 and widget2 have all of those...
i'm trying to construct what i believe would be a fairly simple query against 1 table with just 3 columns. however, with my limited sql knowledge, it feels like i'm going in circles. can any mysql gurus please help?
my table is called "categories" and has the following fields and example data...
Steve,
Yep! That certainly makes sense... only I don't have the destination printers (they can be local printers, network printers, "non-standard" faxing software, etc...), and as you can imagine, each user's machine can have different printers. So it's easier in my case to just pull...
Steve,
Your right, the serial print probably would work, especially if I were sending the reports directly to the printer.
I guess I was trying to open each report in "Preview Mode" in parallel so they each could be faxed or sent to a different printer individually (specify the...
Hey guys! Thanks for your input... I was able to figure it out. Here's what I did:
1) Declare a global variable (in the module header, outside of the subroutine) like this:
'Assume we'll never need more than 25 instances of the
'same report open at once
Dim rpt(1 To 25) As Report
2) set a...
Does anyone know how to open multiple instances of the same report?
I have a report named: rptPOs
I need open multiple instances of the report at one time (so the user will know to print ALL instances of the report).
I'm trying to open each report each report passing different filter criteria...
Thanks again Terry! The crosstab solution makes sense, but I like your self-join solution better. In case anyone is wondering, here's the self-join with multiple option values:
SELECT a.[Index], a.[Option Value],
b.[Option Value],
c.[Option Value],
d.[Option Value]...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.