i develop this code:
SELECT COUNT(NewEmployee.EmployeeID), NewEmployee.EmployeeId,EmployeeName
FROM NewEmployee INNER JOIN NewTimeAttendance
ON NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and NewTimeAttendance.TotalTime is null
and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null)
and (month = 1 or month = 2 or month = 3)
GROUP BY NewEmployee.EmployeeID, EmployeeName
order by EmployeeID
from my previous two questions selecting null stuff and counting issue...that amazing code is working beautifully fine..but now i need to select more than one count...
...searched (google) .... found alias...tried:
SELECT COUNT(NewEmployee.EmployeeID) as attenddays, COUNT(NewEmployee.EmployeeID) as empabsent
, NewEmployee.EmployeeId,EmployeeName
FROM NewEmployee INNER JOIN NewTimeAttendance
ON empabsent =NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and NewTimeAttendance.TotalTime is null
and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
and (month=1 or month =2 or month = 3) ,
attenddays = NewTimeAttendance.EmployeeID
and NewTimeAttendance.TotalTime is null
and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
and (month=1 or month =2 or month = 3)
GROUP BY NewEmployee.EmployeeID, EmployeeName order by EmployeeID
Incorrect syntax near '='.
second try:
SELECT COUNT(NewEmployee.EmployeeID) as attenddays, COUNT(NewEmployee.EmployeeID) as absentdays,
NewEmployee.EmployeeId,EmployeeName
FROM NewEmployee INNER JOIN NewTimeAttendance
ON attenddays(NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and NewTimeAttendance.TotalTime is null
and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
and (month=1 or month =2 or month = 3)) ,
absentdays(NewEmployee.EmployeeID = NewTimeAttendance.EmployeeID
and NewTimeAttendance.TotalTime is null
and (NewTimeAttendance.note = '' or NewTimeAttendance.note is null )
and (month=1 or month =2 or month = 3))
GROUP BY NewEmployee.EmployeeID, EmployeeName order by EmployeeID
Incorrect syntax near '='.
not very good ideas... so ...help
thanks in advance
Ok here's the deal I got one table with a bunch of client information.
Each client makes up to one purchase a year which is represented by an individual row.
there's a column for the year and there's a column the contains a unique identifier for each client. What I need to do is to construct a query that takes last year and this year and shows me which clients were here made a purchase last year but not make a purchase this year.
I also need to build a query that shows me which clients did not make a purchase last year and the year before last but did make a purchase this year.
I have select, insert, update and delete query.
if i have to write all query in same store procedure that is good for performance or i should write all query in separate store procedure?
Hello,
I am making a small personal application regarding my trade of shares of various companies.
The actions can be selling shares of a company or buying. Therefore, the details to be saved in both cases would be:
Number of Shares
Average Price
Would it be better to use a separate tables for "buy" and "sell" or just use one table for "trade" and keep a field that demarcates "buy" from "sell"?
Below is a sample table:
fruits
+-------+---------+
| id | type |
+-------+---------+
| 1 | apple |
| 2 | orange |
| 3 | banana |
| 4 | apple |
| 5 | apple |
| 6 | apple |
| 7 | orange |
| 8 | apple |
| 9 | apple |
| 10 | banana |
+-------+---------+
Following are the two queries of interest:
SELECT * FROM fruits WHERE type='apple' LIMIT 2;
SELECT COUNT(*) AS total FROM fruits WHERE type='apple'; // output 6
I want to combine these two queries so that the results looks like this:
+-------+---------+---------+
| id | type | total |
+-------+---------+---------+
| 1 | apple | 6 |
| 4 | apple | 6 |
+-------+---------+---------+
The output has to be limited to 2 records but it should also contain the total number of records of the type apple.
How can this be done with 1 query?
I have a scenario. Here's my table structure is:
ID LoginDate RemovalDate
----------------------------------------
1 2009/08/01 NULL
2 2009/09/12 2010/01/02
3 2009/08/31 2009/10/29
4 2010/02/17 NULL
5 2009/10/18 2009/11/22
I want a consolidated results of how many ID's were not removed in a particular month. So the result set should be
Date NotRemoved_ID
--------------------------
2009/08 2
2009/09 3
2009/10 3 [One ID got removed in 2009/10]
2010/02 2 [Two got removed in 2009/11 and 2010/01]
Please help.
For those of you who live and breath database design, have you ever found compelling reasons to have multiple FK's in a table that all point to the same parent table?
We recently had to deal with a situation where we had a table that contained six columns which were all FK columns to the same parent table. We're debating whether this indicates a poor design on our part or whether this is more common than we think.
Thanks very much.
What data type should I use for data that can be very short, eg. html link (think twitter), or very long eg. html blog post (think wordpress).
I am thinking if I use varchar(4000), it maybe too short for a html formated blog entry? but if I use text, it will take up more space and is less efficient?
I am trying to add the SQL_CALC_FOUND_ROWS into a query (Please note this isn't for pagination)
please note I am trying to add this to a cakePHP query the code I currently have is below:
return $this->find('all', array(
'conditions' => $conditions,
'fields'=>array('SQL_CALC_FOUND_ROWS','Category.*','COUNT(`Entity`.`id`) as `entity_count`'),
'joins' => array('LEFT JOIN `entities` AS Entity ON `Entity`.`category_id` = `Category`.`id`'),
'group' => '`Category`.`id`',
'order' => $sort,
'limit'=>$params['limit'],
'offset'=>$params['start'],
'contain' => array('Domain' => array('fields' => array('title')))
));
Note the 'fields'=>array('SQL_CALC_FOUND_ROWS',' this obviously doesn't work as It tries to apply the SQL_CALC_FOUND_ROWS to the table e.g. SELECTCategory.SQL_CALC_FOUND_ROWS,
Is there anyway of doing this? Any help would be greatly appreciated, thanks.
I am using the insert() function from Zend_Db_Table_Abstract.
The data being inserted is user input, so naturally I am curious if ZF does the data cleansing for me, or if I should do it myself before I call the insert() function.
I have a large number of rows that I would like to copy, but I need to change one field.
I can select the rows that I want to copy:
select * from Table where Event_ID = "120"
Now I want to copy all those rows and create new rows while setting the Event_ID to 155. How can I accomplish this?
I have a 1 : M relationship.
I built a dynamic query based on input from users to return the listing of parents entities along with their children (using predicate builder:
(done successfully new TDataContext().Ps.Where(predicate) )...
but need to order the results by a field found only on the child entities.
I'm at a loss: new TDataContext().Ps.Where(predicate).OrderBy(p = p.Cs. ??)
where Ps = parents collection relationship with Cs = child entities
any help appreciated.
I am trying to write a query to select all records from users table where User_DateCreated (datetime field) is = 3 months from today.
Any ideas? Thanks!
I design my database incorrectly, should I fix this while its in development?
"user" table is suppose to have a 1.1 relationship with "userprofile" table
however the actual design the "user" table has a 1.* relationship with "userprofile" table.
Everything works! but should it be fixed anyways?
Hi
In my mode I am selecting a field as
$query1 = $this->db->query("SELECT dPassword
FROM tbl_login
WHERE dEmailID='[email protected]'");
How to return dpassword as a variable to my controller
I tried this way return dpassword;
I've a typical scenario & need to understand best possible way to handle this, so here it goes -
I'm developing a solution that will retrieve data from a remote SOAP based web service & will then push this data to an Oracle database on network.
Also, this will be a scheduled task that will execute every 15 minutes.
I've event queues on remote service that contains the INSERT/UPDATE/DELETE operations that have been done since last retrieval, & once I retrieve the events for last 15 minutes, it again add events for next retrieval.
Now, its just pushing data to Oracle so all my interactions are INSERT & UPDATE statements.
There are around 60 tables on Oracle with some of them having 100+ columns. Moreover, for every 15 minutes cycle there would be around 60-70 Inserts, 100+ Updates & 10-20 Deletes.
This will be an executable jar file that will terminate after operation & will again start on next 15 minutes cycle.
So, I need to understand how should I handle WRITE operations (best practices) to improve performance for this application as whole ?
Current Test Code (on every cycle) -
Connects to remote service to get events.
Creates a connection with DB (single connection object).
Identifies the type of operation (INSERT/UPDATE/DELETE) & table on which it is done.
After above, calls the respective method based on type of operation & table.
Uses Preparedstatement with positional parameters, & retrieves each column value from remote service & assigns that to statement parameters.
Commits the statement & returns to get event class to process next event.
Above is repeated till all the retrieved events are processed after which program closes & then starts on next cycle & everything repeats again.
Thanks for help !
My database has around 25 core numbers, in that weekly basis I need to create an index and drop index. While creating the index it takes long time to complete, my log file also keeps on increasing, and when I delete some numbers from that table also taking too much time (because weekly basis I have to delete 30 to 50 lack numbers and add 30 to 40 lack new number also).
Can u please give me the proper solution..