SQL using sum to count results of multiple subqueries

Posted by asdas on Stack Overflow See other posts from Stack Overflow or by asdas
Published on 2010-05-25T17:32:02Z Indexed on 2010/05/25 18:31 UTC
Read the original article Hit count: 282

Filed under:
|
|
|

I have a table with 2 columns: integer and var char. I am given only the integer values but need to do work on the var char (string) values.

Given an integer, and a list of other integers (no overlap), I want to find the string for that single integer. Then I want to take that string and do the INSTR command with that string, and all the other strings for all the other integers. Then I want the sum of all the INSTR so the result is one number.

So lets say I have int x, and list y=[y0, y1, y2].

I want to do 3 INSTR commands like

SUM(INSTR(string for x, string for y0), INSTR(string for x, string for y1), INSTR(string for x, string for y2))

I think im going in the wrong direction, this is what I have. Im not good with sub queries.

SELECT SUM
(
  SELECT INSTR
  (
    SELECT string FROM pages WHERE int=? LIMIT 1,
    (
      SELECT string FROM pages WHERE id=? OR id=? OR id=? LIMIT 3
    )
  )
)

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql