我从多个列计算值,如下所示:
SELECT COUNT(column1),column1 FROM table GROUP BY column1
SELECT COUNT(column2),column2 FROM table GROUP BY column2
SELECT COUNT(column3),column3 FROM table GROUP BY column3
Run Code Online (Sandbox Code Playgroud)
这将返回例如column1数组(attr1 => 2000,attr2 => 3000 ...)(每列具有特定值和少量值).问题是我的应用程序中的"表"可以是带有一些连接和where子句的查询,可能需要0.1秒.通过做所有计数,每次再次计算"表",这是不必要的.有没有办法用一个查询获取我想要的结果,或"缓存"生成表的查询?否则我相信非规范化将是这里唯一的解决方案.我想要与上述查询相同的结果.我正在使用mysql-myisam.
应该用两个或三个表实现两个表之间的一对多关系?例如,我们应该:
author(id,otherAttributtes)
books(id,authorid,otherAttributes)
Run Code Online (Sandbox Code Playgroud)
要么
author(id,otherAttributtes)
books(id,otherAttributes)
authorConnectsBooks(authorid,booksid)
Run Code Online (Sandbox Code Playgroud)
我更喜欢第一种方法,但我已经看过很多次第二种和更复杂的应用程序.第一种方法有任何缺点,或者只是个人的方式可以遵循?
我的jquery代码:
img[i]='img-src';
$("#popimage1").attr("src",img[i]);
alert($("#popimage1").width()); //doesn't give the width of the current image, but it gives for the previous, and for first null
Run Code Online (Sandbox Code Playgroud)
我的HTML代码:
<img src="" id="popimage1"/>
Run Code Online (Sandbox Code Playgroud)
所以概念是我用jquery为每个i加载不同的图像src,然后我用宽度和高度做一些计算.问题是我用前一个计数器i得到了图像的值.通过推杆我做了一个临时的解决方案
$("#popimage1").hide();
setTimeout(alert($("#popimage1").width(),2000);
$("#popimage1").show();
Run Code Online (Sandbox Code Playgroud)
但它总是不起作用,并导致不必要的超时.而不是警报有另一个使用img宽度和高度的函数,我只是为了你的方便写了警报.任何帮助赞赏!