sql中的這樣的子查詢不行嗎

2023-01-31 21:10:59 字數 1450 閱讀 4059

1樓:老師小喬

我覺得這個地方很別捏:where k1=all(select k1=

是不是可以寫成:where k1 in (select……)

另外這一段**:select k1=

case

when net_yxrs/30-round(net_yxrs/30,0,1)<=0.3 then round(net_yxrs/30,0,1)

when net_yxrs/30-round(net_yxrs/30,0,1)<=0.7 then round(net_yxrs/30,0,1)+0.5

else round(net_yxrs/30,0,1)+1

endfrom daochu

where t_zjjs=0000107

請問是不是寫成檢視之後然後在進行查詢操作更為方便更為易懂呢?另外兩個when中,一個小於等於0.3,一個小於等於0.

7,如果是等於0.2怎麼辦?執行哪一個條件?

這僅僅只是我的一個質疑。

以下是我的寫法:

create view select_k1

asselect

case k1

when net_yxrs/30-round(net_yxrs/30,0,1)<=0.3 then round(net_yxrs/30,0,1)

when net_yxrs/30-round(net_yxrs/30,0,1)<=0.7 then round(net_yxrs/30,0,1)+0.5

else round(net_yxrs/30,0,1)+1

(以上暫且沿用你的寫法,還請你驗證一下我的質疑)

end as _k1

from daochu

where t_zjjs=『0000107』(此處是不是得每次傳值使用啊?如果是每次的值不一樣,又是另外一種情況了)

然後:select a.k1_xz

from sk_k1 a,select_k1 b

where a.k1=b._k1

希望對你有所幫助

2樓:匿名使用者

select k1_xz

from sk_k1

where k1 in (select

case

when net_yxrs/30-round(net_yxrs/30,0,1)<=0.3 then round(net_yxrs/30,0,1)

when net_yxrs/30-round(net_yxrs/30,0,1)<=0.7 then round(net_yxrs/30,0,1)+0.5

else round(net_yxrs/30,0,1)+1endfrom daochu

where t_zjjs=0000107)

3樓:

where k1=all(select k1=

這裡這個all有用?

sql問題子查詢返回的值不止,sql 問題子查詢返回的值不止一個。

解決方法如下 返回一個值 返回多個說明資料庫中滿足使用者查詢條件的記錄有多個,要返回一個就說明使用者的查詢條件不夠,再加條件控制就行了,比如在語句末尾再加 and 如果使用者問的是如何在後臺程式中接收的話,用list可以,一個節點接收result的一行值,讀取的時候遍歷list就行了。update ...

sql中查詢分類彙總的問題

select f1.id,f1.name,sum1 as sum f1 sum2 as sum f2 sum1 sum2 as sum f1 f2 from select tab1.id,name,fl,sum sz as sum1 from tab1,tab2 where tab1.id tab2...

如何動態改變TQUERY中的SQL的查詢語句

可以的。在這裡你不妨把sql語句看成一個普通的字串,這樣所要做的就是字串的連線而已。如 設tstatus偉字串型 query1.sql.add select from huzwhere status 有效 and tstatus edit1.text 不過我覺得還是用引數比較好。象這樣 query1...