1樓:匿名使用者
老大,你這個好複雜喲,呵呵。。。select sum(price) from a where typeid=1) 水費, (select sum(price) from a where typeid=2) 像這個語句裡面,作用域不一樣了,所以寫別名他找不到了。建議你把(select gsname, quname, num, price, typeid from mingxi, users, fenqu where and and xzid=1)和(select gsname, quname, num, price, typeid from mingxi, users, fenqu where and and xzid=2)寫成檢視,然後這樣用:
select , sum( 民用水量,select sum(price) from 你的顫桐檢視a where typeid=1) 水費, (select sum(price) from 你的檢視a where typeid=2) 違約缺碼金,select sum(price) from 你的檢視a where typeid=3) 維修費, (select sum(price) from 你的檢視a where typeid=4) 維護費,sum( 商用水量,select sum(price) from 你的檢視b where typeid=1) 水費, (select sum(price) from 你的檢視b where typeid=2) 違約金,select sum(price) from 你的檢視b where typeid=3) 維修費, (select sum(price) from 你的檢視b where typeid=4) 維護茄扮坦費。
from 你的檢視a as a,你的檢視b as bgroup by ,go
2樓:匿名使用者
採用lin的寫法吧,把from那部分寫到試試。
3樓:五顯蝶
是無效的標示符!是不是別名不能再進行運算,也不能用在where 語句中的條件這樣分析一下吧,當你select 1 as a,2 as b from dual的時候,a和b都。
4樓:網友
問題出在這裡: and xzid=1) as a,你本來有乙個表是a,你有用a作為別名。改下名字吧。
5樓:網友
好像表的別名不要加 as 吧,像下面這樣寫就行了。
select * from (select * from a ) a;
sqlserver中,在where條件中使用別名,列名無效
6樓:網友
使用子查詢唄。
select * from
select ,isnull(, '') +isnull(, '')+ isnull(, '') +isnull(, '')+ isnull(, '') +isnull(, '') as pdt ,,from cus_product p) tinner join cus_basic b on = ,(select top ( 1 - 1 ) 25 + 25 )
row_number() over ( order by sort desc ) rowid ,id
from cus_product pwhere 1 = 1
and like '%四川%' 求**能讓這句生效) temp
where = 1
and =and > 1 - 1 ) 25 )order by asc
sql語句中,為什麼where子句不能使用列別名,而order by卻可以?
7樓:
可以啊,select * from 表 as 別名where 別名。欄位名=...
order by 別名。欄位名。
沒問題啊 ,如果你的sql有問題貼出來看看。
8樓:
執行順序。
where=>別名=>order by.不需要解釋為什麼了吧。
9樓:網友
1安裝oracle client
2 add new service (寫客戶端檔案)配置例項名,ip,埠號。
3 用sqlplus訪問資料庫。
10樓:網友
沒有為什麼~規定~~就想為什麼叫sql一樣~~~
sql語句中的別名為什麼不能用啊
11樓:網友
這樣分析一下吧,當你select 1 as a,2 as b from dual的時候,a和b都是表示你的列別名!所以如果你在。
後面再加上a+b這是沒有意義的,因為這裡的a和b都只是乙個識別符號,他讀不出1和2的。
select a+b from (select 1 as a,b as b from dual ) as temp;
中a和b就可以輸出3,因為你括號裡面的返回的是這樣的:a b
這樣你就明白了吧,還要提醒一點是select語句放在from後,要加別名的,不然會出錯。
12樓:小狼哥哥琴島
要求和的話要用函式:sum(a+b).
sql語句中別名怎麼使用
13樓:網友
這裡不能用rn
你的意思可能是。
select a.* from (select t.*,rownum rn from emp t order by sal desc) a where rn<10
這樣就可以用了,在where條件裡面不能用本層查內詢的欄位的別名。容。
14樓:dab小飛
與sql語句的執行順序有關。
先執行的where 後執行的select ,所以在select中的別名 where 獲取不到。
15樓:網友
列的別名 只是為了 顯示是 看出來。
表的別名 是操作用 的 你就這麼理解就可以了。
為什麼在sql語句的group by裡面不可以使用別名
16樓:
如下的sql語句:
select sum(num),case type when 1 then '類別1' else '類別2' end as utype from user group by utype;
執行時會報invalid identifi的錯誤,這是因為在sql執行的時候,where和group語句在欄位分類之前就已經執行了,在此期間,別名還沒有生效,因此找不到指定別名的欄位,報錯。
解決辦法,將語句改為:
select sum(num), from user,(select id,case type when 1 then '類別1' else '類別2' end as utype from user) bieming ehere group by ;
就是使用乙個子查詢將別名欄位單獨拿出來,然後再彙總。
sql語句問題,sql語句問題
group by是分組函式 描述可能不準確 count是聚合函式,一定要確定分組的維度,才能在該維度下使用聚合函式進行統計,你要新增dname,那麼dname應該和deptno一起作為統計的維度,又dname在dept表中需要進行表關聯,所以 sql select deptno,dname,coun...
SQL別名相加
select distinct a1.a1,a1.a2,a2.b2 as 列1,a3.c3 as 列2,a2.b2 a3.c3 as 列3from a a1,select distinct b2 from b where a.a1 b.a1 a2,select distinct c2 from c ...
Sql語句的TOP用法有哪些,Sql語句的TOP用法
top的域名你值得擁有 新國際頂級域,你值得擁有.top top子句用於規定要返copy 回的記錄的數目。對於擁有數千條記錄的大型表來說,top 子句是非常有用的。sqlserver 的語法 select topnumber percent column name s from table name...