sql接口不允许我在我的SQL查询中加分号。我该怎么做才能绕过这个?
import numpy as np
import theano
import theano.tensor as T
from theano.tensor.nnet import conv2d
# original image
img = [[[1, 2, 3, 4], #R channel
[1, 1, 1, 1], #
[2, 2, 2, 2]], #
[[1, 1, 1, 1], #G channel
[2, 2, 2, 2], #
[1, 2, 3, 4]], #
[[1, 1, 1, 1], #B channel
[1, 2, 3, 4], #
[2, 2, 2, 2],]]#
# separate and reshape each channel to 4D
R = np.asarray([[img[0]]], dtype='float32')
G = np.asarray([[img[1]]], dtype='float32')
B = np.asarray([[img[2]]], dtype='float32')
# 4D kernel from the original : [1,0,1]
kernel = np.asarray([[[[1],[0],[1]]]], dtype='float32')
# theano convolution
t_img = T.ftensor4("t_img")
t_kernel = T.ftensor4("t_kernel")
result = conv2d(
input = t_img,
filters=t_kernel,
filter_shape=(1,1,1,3),
border_mode = 'half')
f = theano.function([t_img,t_kernel],result)
# compute each channel
R = f(R,kernel)
G = f(G,kernel)
B = f(B,kernel)
# reshape again
img = np.asarray([R,G,B])
img = np.reshape(img,(3,3,4))
print img
如果我杀了分号,界面会给出:
错误:ORA-00907:缺少右括号。
如果我输入分号,界面会给出:
错误:ORA-00911:无效字符
在我的sqllite程序中,查询在没有select country.country, count(customer.customer_id) as country_count
from customer
join address on customer.address_id = address.address_id
join city on address.city_id = city.city_id
join country on city.country_id = country.country_id
group by country.country_id
order by country_count desc;
limit 10
的情况下工作正常。
答案 0 :(得分:2)
在 elif inst ['Events'][0]['Code'] == "instance-stop":
if "[Completed]" in inst['Events'][0]['Description']:
print "Nothing to do here"
之后加分号,分号始终位于查询的 end 。
LIMIT
请注意,这是MySQL语法,因此这个查询引发错误并不奇怪。您应该使用order by country_count desc
limit 10;
:
rownum
答案 1 :(得分:2)
您正在寻找此
SELECT *
FROM (SELECT country.country,
Count(customer.customer_id) AS country_count
FROM customer
JOIN address
ON customer.address_id = address.address_id
JOIN city
ON address.city_id = city.city_id
JOIN country
ON city.country_id = country.country_id
GROUP BY country.country_id
ORDER BY country_count DESC)
WHERE ROWNUM <= 10
在Oracle LIMIT
关键字中不支持使用ROWNUM
来限制记录
答案 2 :(得分:1)
如果您使用的是Oracle 12,则可以使用FETCH FIRST:
SELECT country.country, COUNT (customer.customer_id) AS country_count
FROM customer
JOIN address ON customer.address_id = address.address_id
JOIN city ON address.city_id = city.city_id
JOIN country ON city.country_id = country.country_id
GROUP BY country.country_id
ORDER BY country_count DESC
FETCH FIRST 10 ROWS ONLY
如果没有,实际上FETCH FIRST就是这样的语法糖:
SELECT country, country_count
FROM ( SELECT country.country,
COUNT (customer.customer_id) AS country_count,
ROW_NUMBER () OVER (ORDER BY COUNT (customer.customer_id) DESC) rn
FROM customer
JOIN address ON customer.address_id = address.address_id
JOIN city ON address.city_id = city.city_id
JOIN country ON city.country_id = country.country_id
GROUP BY country.country_id)
WHERE rn <= 10
ORDER BY country_count DESC
您可以在Oracle版本中使用它&lt; 12