Tagged Questions
0
votes
0answers
10 views
SQL fiscal periods over multiple years
I am writing a command for Crystal reports in Oracle SQL Dev and i have ran into a problem. My User wants to have parameters that allow them to use a starting year/period in the format 'yyyymm' and ...
0
votes
2answers
16 views
Rewrite object.count(conditions: [ ]) SQL query
I have a question and answer model, answers belong to questions and a question has many answers. Answers have a boolean :correct column so answers can be marked as correct.
The code below checks ...
0
votes
4answers
25 views
SQL Ordering Data from row “n+1” to “n-1”
I have a simple question SQL. Consider a row "n", how can we order rows by id (for example), but start from the row "n+1" and end to the row "n-1" ?
Thanks !
0
votes
3answers
31 views
MySQL gives correct output but Java raise exception
I want to show following information -
Date Flight | Name Departure Time | Business Class Availability | Executive Class Availability | Economy Class Availability
Now all the information are in ...
0
votes
0answers
63 views
Select the 5 bests from 5 categories
I have a table userpage with the fields id, userid and pageid. There's a table page with fields id and categoryid as well.
With userpage, I link users to pages. This can happen only once for one ...
5
votes
2answers
66 views
Limit SQL by the sum of the row's value
So I'm kind of stumped here, I have a table setup like this
+-----------+------+
| Timestamp | Size |
+-----------+------+
| 1-1-13 + 10.3 +
+-----------+------+
| 1-3-13 + 6.7 +
...
0
votes
0answers
46 views
return nothing from multiple tables join in mysql - three tables
I wrote the below sql query to get one video that not seen by the current user IP. But I always get no video. This is my code
SELECT ...
3
votes
2answers
68 views
Select SQL one row more
I have a site with a database with user, I have three simple table:
- users
- user_profile (with an external key called: user_id to table users)
- user_image_profile (with an external key called: ...
0
votes
2answers
47 views
Subqueries on subqueries
I'm trying to create a select statement
I need to gather from one table a record that equals the same code used in another table.
better put, a client selects from a drop down list a city and a ...
1
vote
3answers
57 views
Simple select query not working?
PROVINCE -- varchar(25)
SELECT * FROM listings WHERE PROVINCE='Bakersfield'
Returns empty resultset when entries with Bakersfield as province exist
I am pretty unsure as to why. When I remove ...
2
votes
2answers
51 views
Creating complex IF, OR, NOT & AND SQL queries (MySQL)
(Apologies if this a duplicate - I have tried searching, but I may not know the right word for what I'm trying to achieve - feel free to correct me!)
The Background
So I have a PHP based app ...
0
votes
3answers
30 views
SQL: Finding Average Score
Given the table, I am looking for a query to calculate the average score of a given question for a given teacher.
If I was going to add another column to the table like SCHOOLID and wanted to have ...
1
vote
1answer
21 views
Is it possible changing the result columns?
I have a table MyTable with 6 columns:
When I write : select * from MyTable I get this result
NAME | LAST_NAME | FIRST_NAME | AGE | SALARY | ID
what I want is to change their order, I want ...
0
votes
3answers
31 views
SQL Timestamp Subtraction to get number of days
In the code below instead of active age I need to do a calculation with Open_time and the current time.
In other words i need to do if current time minus open_time is between 0 and 30, or 31 and 60, ...
1
vote
1answer
30 views
Query Using Django ORM Many To Many field
I'm trying to make a query to my bd using Django ORM but I need some help.
Models:
class Participant(models.Model):
username = models.CharField(max_length=20)
username.primary_key = True
...
0
votes
1answer
25 views
Running a query from Django ModelForm
I have the following existing code to work with (I included just the relevant parts).
models.py
class Customer(models.Model):
customer_id = models.CharField(primary_key=True, max_length=16)
...
0
votes
1answer
22 views
SQL Syntax for date range in a multiple search query
I have this code written so far and it works for what I am doing but if I search for June 13 it will only look up until June 12, can someone help me figure whats wrong in my code? or where I can add a ...
0
votes
1answer
30 views
SQL Query, return all children in a one-to-many relationship when one child matches
I'm working on enhancing a query for a DB2 database and I'm having some problems getting acceptable performance due to the number of joins across large tables that need to be performed to get all of ...
1
vote
5answers
71 views
How to combine two sql queries from same table
I have the following (example) data in a table
Value, Date, Device
I use the data to do simple SLA calculations, i.e. how many times during business hours was the data below a certain threshold.
...
1
vote
1answer
23 views
Update a column in a database depending on the text in another column?
I have a column of type int and a column of type varchar(255).
Is it possible for me to loop through every row in my database and check for a certain string in the varchar(255) column, if that ...
0
votes
4answers
42 views
Query ORA-01791 Error due to ||','||
I'm getting an error: ORA-01791: not a SELECTed expression when I try to run this query. I am able to run it when the SELECT is comma seperated (AH.NAME, REPLACE(A.ACTIVE_DC,',','/'),etc) but with the ...
0
votes
1answer
54 views
How can I change this SELECT statement into an UPDATE statement?
I've managed to write a query which pulls back orders which do not have items in a separate table. I'd now like to update the xxx_orders based on the record set returned. Can it be done in one query?
...
-2
votes
8answers
72 views
SQL query takes very very long, is it faulty or inefficient? [closed]
I have a database table where I want to select all rows for which there is a row with the same field1 and field2=5. I made the following SQL query:
SELECT * FROM `table`
WHERE `field1` IN (SELECT ...
2
votes
1answer
24 views
Array aggregation for all columns in a table in Postgres
WITH Dept(DName, HeadCount) AS (
VALUES ('D1', 5), ('D2', 6), ('D3', 7)
)
Select array_agg(DName), array_agg(HeadCount) from Dept
The above query will yield.
"{D1,D2,D3}";"{5,6,7}"
Is there ...
1
vote
1answer
27 views
How to select the duplicate rows / records in a large table
I have an oracle table with 35 columns, one of which is a unique id.
This table has a few entries / rows that are duplicate.
When I do a select distinct (*) i get a number x
When I do a select ...
0
votes
1answer
23 views
How to put a base64 image in the SQLSERVER Image type?
I'm trying to put a base64 String in the SqlServer on Image type or VarBinary(MAX) on Sqlserver's Image type.
for this I tryied to use
byte[] b = Convert.FromBase64String(mybase64); and put it as a ...
0
votes
3answers
33 views
Database Query for Mulitple Instances
I have a database table of all US zip codes and their corresponding state and congressional district like this below..
id | zipcode | state_abbr | district
1 30080 GA 1
2 ...
0
votes
2answers
47 views
Can This Query Be Written With Cdbcriteria (Yii Framework)?
I have this query and I want to write it with CDBCriteria . Can it be written with CDBCriteria? I dont know how to write this query with CDBcriteria in Yii framework .
Thanks for your time.
...
-1
votes
1answer
47 views
SQL query to find all the columns that are of the type Datatime
I have to find all the columns in a table where the datatype for that column is datetime.
Any ideas on how to do this?
IE
Select * FROM Table1 WHERE datatype = datetime.
0
votes
0answers
43 views
remove default sort from sql query and
I want to get records sorted as they are in the query :
SELECT `month`, SUM(order_quantity) AS order_quantity FROM" +
"( SELECT MONTH(date_livraison) AS month, COUNT(*) AS ...
0
votes
1answer
37 views
Query to arrange the order of execution of Where Clauses
I have a database where some parts are indexed why some parts are not properly indexed due to business requirements using Entity Attribute Value(See here : Optimizing search for values in columns in ...
1
vote
3answers
31 views
How should I handle TableModel updates when working with SQL?
My GUI includes a JTable and several forms that may trigger INSERT, UPDATE or DELETE SQL queries. Whenever it happens, I want my table to be updated accordingly. Since both the TableModel and the ...
0
votes
2answers
56 views
Whats wrong with query? wrong syntax error? Group by no working
I have written a query
(SELECT TimeStamp, AVG(FwdHr), W
FROM Meter_Data
WHERE (TimeStamp Between 1370476500 AND 1370477100 AND DeviceID = '1'
GROUP BY MeterID ORDER BY TimeStamp)
UNION
...
0
votes
2answers
36 views
Access adding column of type decimal(number with fieldsize decimal)
In access 2007 how to add a column of type decimal to the access table using query?
In GUI i can select data type as Number and for that i can set field size as Decimal.
Now i want to do the same ...
-2
votes
0answers
17 views
MSSQL: Bulk Insert through netwok [migrated]
Can someone help me with these?
BULK INSERT DATABESE01.dbo.TABLE01
FROM '\\COMPUTER01\FOLDER01\TextFile.txt'
WITH
(
FIELDTERMINATOR = ' ',
rowterminator = '\n',
tablock
)
The error ...
2
votes
3answers
41 views
SQL select if number is between interval
I'm busy building up a catalog site for a client of mine, and need to tweek the search a bit.
The catalog contains a whole bunch of products. Each product has the ability to contain a single, ...
0
votes
2answers
20 views
Update Command with Case in SQLite
I want to update table A in such a way that if the attribute of the table column is desired then only it will change otherwise it wont change..
Update table A set B="abcd" ,C= (case when C="abc" then ...
0
votes
3answers
30 views
sql query to select columns by condition on specific column(with out aggregate function) with group by
I am trying to write a sql query with group by so that i can get columns from the same raw by condition on one column, I can not use aggregate function
e.g Employee table
EmpId data1 data2 data3 ...
1
vote
3answers
33 views
Postgres selecting only columns that meet a condition
If I have a database table t1 that has the following data:
How can I select just those columns that contain the term "false"
a | b | c | d
------+-------+------+------
1 | 2 | ...
0
votes
1answer
20 views
Using an Int as the database selection Argument
I know this will seem like an obvious question, but i've yet to find an answer, so any help would be appreciated. I want to query a SQL database based on an int but all the examples and tutorials that ...
1
vote
1answer
26 views
MySQL - Selecting rows that do not have a match or that have with a condition
I can't figure this out so far, I have these tables:
students - Columns: id, name
stud_class - Columns: students_id, class_id
class - Columns: id, courses_id
courses - Columns: id, name
I need ...
0
votes
3answers
33 views
SQL query - Joining a many-to-many relationship, filtering/joining selectively
I find myself in a bit of an unworkable situation with a SQL query and I'm hoping that I'm missing something or might learn something new. The structure of the DB2 database I'm working with isn't ...
1
vote
0answers
42 views
Is it possible to replace a value used in an SQL Query with a IN (SELECT…) that returns that same value?
The following QUERY #1 returns the correct results when value "1010" is used:
SELECT *
FROM iterations $iterations2, experiments $experiments1, clients $clients1
WHERE $experiments1.id = ...
0
votes
4answers
25 views
access syntax error in FROM
I need to do either a UNION ALL or an OUTER JOIN to link two tables. I thought I had the syntax fine given that I used the same format from microsoft website ...
1
vote
2answers
50 views
Is there a way to do conditional logic in a SQL query?
So I have a fairly long complex query but the gist is that the query's basic functionality looks like this SELECT verification_id FROM verification_table
The verification_id returns an integer from ...
0
votes
3answers
32 views
SQL selecting through a join table with a where or clause
two tables:
tasks - id, creator_id (rest not relevant)
tag_tasks - tag_id, task_id
I want to grab tasks through tag_tasks via an array of tag ids, BUT also grab tasks that have a certain ...
0
votes
4answers
23 views
Select duplicate records info
I have a person table:
Phone | Id1 | Id2 | Fname | Lname| Street
111111111 | A1 | 1000 | David | Luck | 123 Main Street
111111111 | A2 | 1001 | David | Luck | blank
111111111 | A3 | 1002 | David ...
-2
votes
5answers
48 views
How can I see which tables are used in a view?
I have some views in SQL server manager, and I want to see which tables are being used to supply the data to the view. How do I do this?
0
votes
1answer
31 views
print data even if it is null/empty/none existed. Note: some cells doesn't exist
I have a problem where i have searched for hours for a solution. But until now, I haven't found any. The problem is that i have the following query:
$sql = "SELECT
MONTH( i.invoicedate ...
0
votes
2answers
26 views
Date period spread among seasons
In my MySQL database table I have the following date periods (seasons):
sstart,send,sname
2013-05-01,2013-05-31,'season1'
2013-06-01,2013-06-30,'season2'
I'd like to create SQL query which will for ...