I'm making a wp guestbook and i've made a mistake somewhere. At first i've tried to use join but coud not get it to work properly because of all those conditions so i wrote this:

我正在制作一本wp留言簿,我在某个地方犯了一个错误。起初我已经尝试使用join但是由于所有这些条件而无法让它正常工作所以我写了这个:

$query = "  
        (select *,
        (select count(cid) from ctable WHERE nid = vid) as posts,
        (select timestamp from ctable where nid = vid order by timestamp desc limit 1) as lt,
        (select count(vid) from ntable) as total
        FROM ntable
        )";

It does exactly what it supossed to do but it is very slow. I know i shout use join but i cant figure it out.

它确实完成了它所做的事情,但它非常缓慢。我知道我大喊使用加入,但我无法弄明白。

3 个解决方案

#1


0

As per my Exp level ..try to use the nolocks as I updated your query that is ,

按照我的Exp级别..来使用nolocks,因为我更新了你的查询,

$query = '(select *,
        (select count(cid) from ctable with(nolock) WHERE nid = vid) as posts,
        (select timestamp from ctable with(nolock) where nid = vid order by timestamp desc limit 1) as lt,
        (select count(vid) from ntable with(nolock)) as total
        FROM ntable with(nolock)
        )';

and you are using the Order by for with timestamp column and instead of that use getdate()-1(means days count for the old data so that query will improve its performance.)

并且您使用Order by for timestamp列而不是使用getdate() - 1(表示旧数据的天数,以便查询将提高其性能。)

更多相关文章

  1. 请问用PL/SQL如何判断两个日期之间相差的天数?

随机推荐

  1. Android开发小知识文章目录
  2. Android(安卓)App状态栏动态显示隐藏
  3. Android UI 之 onTouchEvent, onClick及o
  4. Android Layout布局文件里的android:layo
  5. 哪些年遇到过的Andriod问题(5)This text
  6. Android:在Eclipse下开发android应用产生
  7. android中国风笔记源码,金鱼游动动画源码
  8. (转帖)Android系列之浅谈Android 3D旋转
  9. android 图片的 放大 缩小 移动
  10. 使用Vitamio打造自己的Android万能播放器